Skip to content

Commit 19b20d2

Browse files
author
Kapil Borle
committed
Use cached strings to display states
1 parent 00c6a13 commit 19b20d2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/animatedStatusBar.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ export function setAnimatedStatusBarMessage(text: string, hideWhenDone: Thenable
1111
}
1212

1313
class AnimatedStatuBarItem implements StatusBarItem {
14+
private readonly animationRate: number;
1415
private statusBarItem: StatusBarItem;
1516
private maxCount: number;
1617
private counter: number;
1718
private baseText: string;
1819
private timerInterval: number;
19-
private ticks: number;
20+
private elapsedTime: number;
2021
private intervalId: NodeJS.Timer;
22+
private suffixStates: string[];
2123

2224
get alignment(): StatusBarAlignment {
2325
return this.statusBarItem.alignment;
@@ -60,12 +62,14 @@ class AnimatedStatuBarItem implements StatusBarItem {
6062
}
6163

6264
constructor(baseText: string, alignment?: StatusBarAlignment, priority?: number) {
65+
this.animationRate = 1;
6366
this.statusBarItem = window.createStatusBarItem(alignment, priority);
6467
this.baseText = baseText;
65-
this.maxCount = 4;
6668
this.counter = 0;
67-
this.timerInterval = 300;
68-
this.ticks = 0;
69+
this.suffixStates = [" ", ". ", ".. ", "..."];
70+
this.maxCount = this.suffixStates.length;
71+
this.timerInterval = ((1/this.maxCount) * 1000) / this.animationRate;
72+
this.elapsedTime = 0;
6973
}
7074

7175
show(hideWhenDone?: Thenable<any>): void {
@@ -87,11 +91,11 @@ class AnimatedStatuBarItem implements StatusBarItem {
8791

8892
_updateCounter(): void {
8993
this.counter = (this.counter + 1) % this.maxCount;
90-
this.ticks = this.ticks + 1;
94+
this.elapsedTime = this.elapsedTime + this.timerInterval;
9195
}
9296

9397
_updateText(): void {
94-
this.text = this.baseText + ".".repeat(this.counter) + " ".repeat(this.maxCount - this.counter - 1);
98+
this.text = this.baseText + this.suffixStates[this.counter];
9599
}
96100

97101
_update(): void {

0 commit comments

Comments
 (0)