2019-03-31 07:51:17 -05:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
|
|
|
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
export class StatusDisplay implements vscode.Disposable {
|
2019-04-02 12:46:47 -05:00
|
|
|
public packageName?: string;
|
|
|
|
|
2019-03-31 07:51:17 -05:00
|
|
|
private i = 0;
|
|
|
|
private statusBarItem: vscode.StatusBarItem;
|
2019-06-24 05:02:20 -05:00
|
|
|
private command: string;
|
2019-03-31 07:51:17 -05:00
|
|
|
private timer?: NodeJS.Timeout;
|
|
|
|
|
2019-06-24 05:02:20 -05:00
|
|
|
constructor(command: string) {
|
2019-03-31 08:21:14 -05:00
|
|
|
this.statusBarItem = vscode.window.createStatusBarItem(
|
|
|
|
vscode.StatusBarAlignment.Left,
|
|
|
|
10
|
|
|
|
);
|
2019-06-24 05:02:20 -05:00
|
|
|
this.command = command;
|
2019-03-31 07:51:17 -05:00
|
|
|
this.statusBarItem.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public show() {
|
2019-04-02 12:46:47 -05:00
|
|
|
this.packageName = undefined;
|
|
|
|
|
2019-03-31 08:21:14 -05:00
|
|
|
this.timer =
|
|
|
|
this.timer ||
|
|
|
|
setInterval(() => {
|
2019-04-02 12:46:47 -05:00
|
|
|
if (this.packageName) {
|
2019-06-24 05:02:20 -05:00
|
|
|
this.statusBarItem!.text = `cargo ${this.command} [${
|
2019-04-02 12:46:47 -05:00
|
|
|
this.packageName
|
|
|
|
}] ${this.frame()}`;
|
|
|
|
} else {
|
2019-06-24 05:50:34 -05:00
|
|
|
this.statusBarItem!.text = `cargo ${
|
|
|
|
this.command
|
|
|
|
} ${this.frame()}`;
|
2019-04-02 12:46:47 -05:00
|
|
|
}
|
2019-03-31 08:21:14 -05:00
|
|
|
}, 300);
|
2019-03-31 07:51:17 -05:00
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
this.statusBarItem.show();
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public hide() {
|
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
this.statusBarItem.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public dispose() {
|
|
|
|
if (this.timer) {
|
|
|
|
clearInterval(this.timer);
|
|
|
|
this.timer = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusBarItem.dispose();
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private frame() {
|
2019-03-31 08:21:14 -05:00
|
|
|
return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)];
|
2019-03-31 07:51:17 -05:00
|
|
|
}
|
2019-03-31 08:21:14 -05:00
|
|
|
}
|