rust/editors/code/src/commands/watch_status.ts

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-03-31 07:51:17 -05:00
import * as vscode from 'vscode';
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
export class StatusDisplay {
private i = 0;
private statusBarItem: vscode.StatusBarItem;
private timer?: NodeJS.Timeout;
constructor(subscriptions: vscode.Disposable[]) {
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
subscriptions.push(this.statusBarItem);
this.statusBarItem.hide();
}
public show() {
2019-03-31 08:21:14 -05:00
this.timer =
this.timer ||
setInterval(() => {
this.statusBarItem!.text = 'cargo check ' + this.frame();
}, 300);
2019-03-31 07:51:17 -05:00
this.statusBarItem!.show();
}
public hide() {
if (this.timer) {
clearInterval(this.timer);
this.timer = undefined;
}
this.statusBarItem!.hide();
}
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
}