-
Notifications
You must be signed in to change notification settings - Fork 1
/
spinner.js
37 lines (34 loc) · 919 Bytes
/
spinner.js
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
exports.Spinner = function() {
this.cnt = 0;
this.interval = null;
this.spin = function() {
process.stdout.cursorTo(0);
switch (this.cnt) {
case 0:
process.stdout.write(' / ');
break;
case 1:
process.stdout.write(' - ');
break;
case 2:
process.stdout.write(" \\ ");
break;
case 3:
process.stdout.write(' | ');
break;
}
this.cnt++;
this.cnt = (this.cnt > 3) ? 0 : this.cnt;
};
this.start = function() {
this.spin();
this.interval = setInterval(this.spin, 50);
};
this.stop = function(){
if (this.interval) {
clearInterval(this.interval);
}
process.stdout.clearLine();
process.stdout.cursorTo(0);
};
}