1 | 'use strict';
|
2 |
|
3 | var chain = require('es5-ext/lib/Function/prototype/chain')
|
4 | , write = process.stdout.write.bind(process.stdout)
|
5 |
|
6 | , chars = '-\\|/'
|
7 | , l = chars.length
|
8 | , p;
|
9 |
|
10 | p = {
|
11 | next: 0,
|
12 | write: write,
|
13 | throbbed: false,
|
14 | ontick: function () {
|
15 | if (this.throbbed) {
|
16 | write('\u0008');
|
17 | } else {
|
18 | this.throbbed = true;
|
19 | }
|
20 | this.write(chars[this.next++ % l]);
|
21 | },
|
22 | onstop: function () {
|
23 | if (this.throbbed) {
|
24 | write('\u0008');
|
25 | this.next = 0;
|
26 | this.throbbed = false;
|
27 | }
|
28 | }
|
29 | };
|
30 |
|
31 | module.exports = function (interval, formatting) {
|
32 | var o = Object.create(p);
|
33 | if (formatting) {
|
34 | o.write = chain.call(formatting, write);
|
35 | }
|
36 | interval.on('tick', o.ontick.bind(o));
|
37 | interval.on('stop', o.onstop.bind(o));
|
38 | };
|