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;
|
|
|
|
private timer?: NodeJS.Timeout;
|
|
|
|
|
2019-04-13 15:13:21 -05:00
|
|
|
constructor() {
|
2019-03-31 08:21:14 -05:00
|
|
|
this.statusBarItem = vscode.window.createStatusBarItem(
|
|
|
|
vscode.StatusBarAlignment.Left,
|
|
|
|
10
|
|
|
|
);
|
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) {
|
|
|
|
this.statusBarItem!.text = `cargo check [${
|
|
|
|
this.packageName
|
|
|
|
}] ${this.frame()}`;
|
|
|
|
} else {
|
|
|
|
this.statusBarItem!.text = `cargo check ${this.frame()}`;
|
|
|
|
}
|
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
|
|
|
}
|