aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/watch_status.ts
blob: f027d7bbc27ba9f7ae2c540d034b0c895dae61c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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[]) {
        this.statusBarItem = vscode.window.createStatusBarItem(
            vscode.StatusBarAlignment.Left,
            10
        );
        subscriptions.push(this.statusBarItem);
        this.statusBarItem.hide();
    }

    public show() {
        this.timer =
            this.timer ||
            setInterval(() => {
                this.statusBarItem!.text = 'cargo check ' + this.frame();
            }, 300);

        this.statusBarItem!.show();
    }

    public hide() {
        if (this.timer) {
            clearInterval(this.timer);
            this.timer = undefined;
        }

        this.statusBarItem!.hide();
    }

    private frame() {
        return spinnerFrames[(this.i = ++this.i % spinnerFrames.length)];
    }
}