1 | var Spinner = function(text){
|
2 | this.text = text || '';
|
3 | };
|
4 |
|
5 | var spinnerChars = [ '|', '/', '-', '\\' ];
|
6 |
|
7 | Spinner.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 |
|
17 | Spinner.prototype.stop = function() {
|
18 | clearInterval(this.id);
|
19 | };
|
20 |
|
21 | exports.Spinner = Spinner;
|