UNPKG

470 BJavaScriptView Raw
1var Spinner = function(text){
2 this.text = text || '';
3};
4
5var spinnerChars = [ '|', '/', '-', '\\' ];
6
7Spinner.prototype.start = function() {
8 var current = 0;
9 this.id = setInterval(function() {
10 process.stdout.clearLine();
11 process.stdout.cursorTo(0);
12 process.stdout.write(spinnerChars[current] + ' ' + this.text);
13 current = ++current % 4;
14 }, 200);
15};
16
17Spinner.prototype.stop = function() {
18 clearInterval(this.id);
19};
20
21exports.Spinner = Spinner;