-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
80 lines (66 loc) · 1.55 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var moment = require('moment'),
multimeter = require('multimeter')(process),
EventEmitter = require('events').EventEmitter,
util = require('util'),
chalk = require('chalk');
multimeter.charm.on('^C', function () {
//multimeter.charm.reset();
console.log('\n');
process.exit();
});
var Ticker = (module.exports = function (opts) {
EventEmitter.call(this);
opts = opts || {};
this.clock = opts.clock || 40;
this.gain = opts.gain || 10;
this.count = 0;
});
util.inherits(Ticker, EventEmitter);
Ticker.prototype.start = function () {
var self = this;
multimeter.drop(
{
width: 17,
before:
chalk.green('info') +
': [' +
chalk.blue('waitingjerk') +
'] ' +
chalk.bold('FAKE PROGRESS: ') +
chalk.grey('(NOT frozen)') +
chalk.bold(' ~={|'),
after: chalk.bold('|:: '),
solid: {
background: 'black',
foreground: 'green',
text: '✓'
}
},
function (bar) {
var n = 1,
t = self.clock,
k = self.gain;
var iv = setInterval(function () {
var p =
((98 * (t / k + 1)) / t) * k * (n / (n + k * t) - 1 / (1 + k * t)) -
1;
bar.percent(p);
n++;
}, t);
self.on('stop', function (cb) {
clearInterval(iv);
bar.percent(100);
console.log();
multimeter.destroy();
if (cb) {
cb();
}
});
}
);
return this;
};
Ticker.prototype.stop = function (cb) {
this.emit('stop', cb);
return this;
};