setitch-multimeter 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.markdown +14 -14
- package/example/drop.js +10 -9
- package/example/images/drop.png +0 -0
- package/example/images/multibar.png +0 -0
- package/example/images/multirel.png +0 -0
- package/example/images/sum.png +0 -0
- package/example/multibar.js +23 -23
- package/example/multirel.js +24 -24
- package/example/simple_model.js +19 -83
- package/example/single.js +8 -7
- package/example/sum.js +14 -14
- package/example/web_multibar.js +30 -30
- package/example/web_multirel.js +33 -33
- package/example/web_sum.js +23 -23
- package/package.json +9 -6
- package/src/index.js +84 -0
- package/src/lib/bar.js +129 -0
- package/src/simple_model.js +92 -0
- package/index.js +0 -75
- package/lib/bar.js +0 -113
package/README.markdown
CHANGED
|
@@ -3,20 +3,20 @@ multimeter
|
|
|
3
3
|
|
|
4
4
|
Control multiple ANSI progress bars on the terminal.
|
|
5
5
|
|
|
6
|
-

|
|
7
7
|
|
|
8
|
-

|
|
9
9
|
|
|
10
10
|
example
|
|
11
11
|
=======
|
|
12
12
|
|
|
13
13
|
````javascript
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import multimeter from 'setitch-multimeter';
|
|
15
|
+
const multi = multimeter(process);
|
|
16
16
|
|
|
17
|
-
multi.drop(
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
multi.drop((bar) => {
|
|
18
|
+
const iv = setInterval(() => {
|
|
19
|
+
const p = bar.percent();
|
|
20
20
|
bar.percent(p + 1);
|
|
21
21
|
|
|
22
22
|
if (p >= 100) clearInterval(iv);
|
|
@@ -27,18 +27,18 @@ multi.drop(function (bar) {
|
|
|
27
27
|
methods
|
|
28
28
|
=======
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
import multimeter from 'setitch-multimeter';
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const multi = multimeter(stream, ...)
|
|
33
|
+
-------------------------------------
|
|
34
34
|
|
|
35
35
|
Create a new multimeter handle on the supplied stream/process objects, which
|
|
36
36
|
will be passed directly to [charm](https://github.com/substack/node-charm).
|
|
37
37
|
|
|
38
38
|
If you pass in a charm object that will be used instead of creating a new one.
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const bar = multi(x, y, params)
|
|
41
|
+
-------------------------------
|
|
42
42
|
|
|
43
43
|
Create a new progress bar at `(x,y)` with `params` which default to:
|
|
44
44
|
|
|
@@ -50,8 +50,8 @@ Create a new progress bar at `(x,y)` with `params` which default to:
|
|
|
50
50
|
|
|
51
51
|
If `y` is negative or `'-0'` it will be treated as a relative coordinate.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const bar = multi.rel(x, y, params)
|
|
54
|
+
-----------------------------------
|
|
55
55
|
|
|
56
56
|
Create a new progress bar at an absolute `x` and relative `y` coordinate with
|
|
57
57
|
respect to the present `multi.offset`.
|
package/example/drop.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
var multi = multimeter(process);
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
3
2
|
|
|
4
|
-
multi
|
|
3
|
+
const multi = multimeter(process);
|
|
4
|
+
|
|
5
|
+
multi.on('^C', () => {
|
|
5
6
|
multi.charm.cursor(true);
|
|
6
7
|
multi.write('\n').destroy();
|
|
7
|
-
|
|
8
|
+
|
|
8
9
|
process.exit();
|
|
9
10
|
});
|
|
10
11
|
multi.charm.cursor(false);
|
|
11
12
|
|
|
12
|
-
multi.drop(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
bar.percent(p + 1/100);
|
|
13
|
+
multi.drop((bar) => {
|
|
14
|
+
const iv = setInterval(() => {
|
|
15
|
+
const p = bar.percent();
|
|
16
|
+
bar.percent(p + 1 / 100);
|
|
16
17
|
if (p >= 1) {
|
|
17
18
|
clearInterval(iv);
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
multi.charm.cursor(true);
|
|
20
21
|
multi.write('\n').destroy();
|
|
21
22
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/example/multibar.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const multi = multimeter(process);
|
|
4
4
|
multi.on('^C', process.exit);
|
|
5
5
|
multi.charm.reset();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
|
|
7
|
+
const bars = [];
|
|
8
|
+
const progress = [];
|
|
9
|
+
const deltas = [];
|
|
10
10
|
|
|
11
11
|
multi.write('Progress:\n\n');
|
|
12
12
|
|
|
13
|
-
for (
|
|
14
|
-
|
|
13
|
+
for (let i = 0; i < 5; i++) {
|
|
14
|
+
const s = 'ABCDE'[i] + ': \n';
|
|
15
15
|
multi.write(s);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
width
|
|
19
|
-
solid
|
|
20
|
-
text
|
|
21
|
-
foreground
|
|
22
|
-
background
|
|
16
|
+
|
|
17
|
+
const bar = multi(s.length, i + 3, {
|
|
18
|
+
width: 20,
|
|
19
|
+
solid: {
|
|
20
|
+
text: '|',
|
|
21
|
+
foreground: 'white',
|
|
22
|
+
background: 'blue'
|
|
23
23
|
},
|
|
24
|
-
empty
|
|
24
|
+
empty: { text: ' ' },
|
|
25
25
|
});
|
|
26
26
|
bars.push(bar);
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
deltas[i] = 1 + Math.random() * 9;
|
|
29
29
|
progress.push(0);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
multi.write('\nbeep boop\n');
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
progress.forEach(
|
|
34
|
+
let pending = progress.length;
|
|
35
|
+
const iv = setInterval(() => {
|
|
36
|
+
progress.forEach((p, i) => {
|
|
37
37
|
progress[i] += Math.random() * deltas[i];
|
|
38
|
-
bars[i].percent(progress[i]/100);
|
|
39
|
-
if (p < 100 && progress[i] >= 100) pending
|
|
38
|
+
bars[i].percent(progress[i] / 100);
|
|
39
|
+
if (p < 100 && progress[i] >= 100) pending--;
|
|
40
40
|
if (pending === 0) {
|
|
41
41
|
multi.write('\nAll done.\n');
|
|
42
42
|
multi.destroy();
|
|
43
43
|
clearInterval(iv);
|
|
44
|
-
pending
|
|
44
|
+
pending--;
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}, 100);
|
package/example/multirel.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const multi = multimeter(process);
|
|
4
4
|
multi.on('^C', process.exit);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const bars = [];
|
|
7
|
+
const progress = [];
|
|
8
|
+
const deltas = [];
|
|
9
9
|
|
|
10
10
|
multi.write('Progress:\n\n');
|
|
11
11
|
|
|
12
|
-
for (
|
|
13
|
-
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
const s = 'ABCDE'[i] + ': \n';
|
|
14
14
|
multi.write(s);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
width
|
|
18
|
-
solid
|
|
19
|
-
text
|
|
20
|
-
foreground
|
|
21
|
-
background
|
|
15
|
+
|
|
16
|
+
const bar = multi.rel(4, i, {
|
|
17
|
+
width: 20,
|
|
18
|
+
solid: {
|
|
19
|
+
text: '|',
|
|
20
|
+
foreground: 'white',
|
|
21
|
+
background: 'blue'
|
|
22
22
|
},
|
|
23
|
-
empty
|
|
23
|
+
empty: { text: ' ' },
|
|
24
24
|
});
|
|
25
25
|
bars.push(bar);
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
deltas[i] = 1 + Math.random() * 9;
|
|
28
28
|
progress.push(0);
|
|
29
29
|
}
|
|
@@ -31,22 +31,22 @@ for (var i = 0; i < 5; i++) {
|
|
|
31
31
|
multi.offset += 2;
|
|
32
32
|
multi.write('\nbeep');
|
|
33
33
|
|
|
34
|
-
setTimeout(
|
|
35
|
-
multi.offset
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
multi.offset++;
|
|
36
36
|
multi.write('\n boop');
|
|
37
37
|
}, 2000);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
progress.forEach(
|
|
39
|
+
let pending = progress.length;
|
|
40
|
+
const iv = setInterval(() => {
|
|
41
|
+
progress.forEach((p, i) => {
|
|
42
42
|
progress[i] += Math.random() * deltas[i];
|
|
43
|
-
bars[i].percent(progress[i]/100);
|
|
44
|
-
if (p < 100 && progress[i] >= 100) pending
|
|
43
|
+
bars[i].percent(progress[i] / 100);
|
|
44
|
+
if (p < 100 && progress[i] >= 100) pending--;
|
|
45
45
|
if (pending === 0) {
|
|
46
46
|
multi.write('\nAll done.\n');
|
|
47
47
|
multi.destroy();
|
|
48
48
|
clearInterval(iv);
|
|
49
|
-
pending
|
|
49
|
+
pending--;
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}, 100);
|
package/example/simple_model.js
CHANGED
|
@@ -1,89 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
* @param barNames Array of bar names
|
|
3
|
-
* @param makeEven boolean (false) should bar start evenly (from longest bar label/name
|
|
4
|
-
* @returns API: {writeText, updateProgress, close}
|
|
5
|
-
* @constructor
|
|
6
|
-
*/
|
|
7
|
-
function ProgressBar(barNames = [], makeEven = true) {
|
|
8
|
-
let multimeter = require('setitch-multimeter');
|
|
9
|
-
let multi = multimeter(process);
|
|
1
|
+
import ProgressBar from '../src/simple_model.js';
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
let progress = [];
|
|
3
|
+
const bars = ['bar1', 'another bar'];
|
|
13
4
|
|
|
5
|
+
const manager = new ProgressBar(bars, true);
|
|
6
|
+
const delay = async (time = 1000) => new Promise((r) => setTimeout(() => r(null), time));
|
|
14
7
|
|
|
15
|
-
for (let i = 0; i < barNames.length; i++) {
|
|
16
|
-
let s = barNames[i] + ': \n';
|
|
17
|
-
multi.write(s);
|
|
18
8
|
|
|
19
|
-
|
|
9
|
+
(async () => {
|
|
10
|
+
manager.updateProgress(bars[0], 0.1);
|
|
11
|
+
await delay();
|
|
12
|
+
|
|
13
|
+
manager.updateProgress(bars[0], 0.3);
|
|
14
|
+
manager.updateProgress(bars[1], 0.5);
|
|
15
|
+
manager.writeText('aaaaaaaaaaaaa');
|
|
16
|
+
await delay();
|
|
17
|
+
|
|
18
|
+
manager.updateProgress(bars[1], 1);
|
|
19
|
+
manager.writeText('bbbb');
|
|
20
|
+
await delay();
|
|
21
|
+
|
|
22
|
+
manager.close();
|
|
23
|
+
})();
|
|
20
24
|
|
|
21
|
-
let bar = multi.rel(offset, i, {
|
|
22
|
-
width : 80,
|
|
23
|
-
solid : {
|
|
24
|
-
text : '#',
|
|
25
|
-
foreground : 'white',
|
|
26
|
-
// background : 'blue'
|
|
27
|
-
},
|
|
28
|
-
empty : { text : '|' },
|
|
29
|
-
});
|
|
30
|
-
bars.push(bar);
|
|
31
|
-
progress.push(0);
|
|
32
|
-
}
|
|
33
25
|
|
|
34
|
-
multi.offset = 1;
|
|
35
|
-
let lastString = '';
|
|
36
|
-
let lastUsedString = '';
|
|
37
|
-
|
|
38
|
-
function update() {
|
|
39
|
-
if (working === false) { return ; }
|
|
40
|
-
let k = new Array(lastUsedString.length).join(' ');
|
|
41
|
-
multi.write(k);
|
|
42
|
-
multi.write(lastString);
|
|
43
|
-
lastUsedString = lastString;
|
|
44
|
-
|
|
45
|
-
bars.forEach((bar, i) => {
|
|
46
|
-
bar.percent(progress[i]);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
timeout = setTimeout(update, 100);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let timeout = setTimeout(update, 100);
|
|
53
|
-
|
|
54
|
-
let working = true;
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
writeText(text) {
|
|
58
|
-
if (working === false) return null;
|
|
59
|
-
|
|
60
|
-
lastString = text;
|
|
61
|
-
|
|
62
|
-
return this;
|
|
63
|
-
},
|
|
64
|
-
updateProgress(name, percentage) {
|
|
65
|
-
if (working === false) return null;
|
|
66
|
-
|
|
67
|
-
let index = barNames.indexOf(name);
|
|
68
|
-
if (index === -1) return -1;
|
|
69
|
-
|
|
70
|
-
percentage = Math.round(percentage * 10000)/10000;
|
|
71
|
-
|
|
72
|
-
progress[progress.length -1 -index] = percentage;
|
|
73
|
-
if (percentage === 1) setTimeout(update);
|
|
74
|
-
return this;
|
|
75
|
-
},
|
|
76
|
-
close() {
|
|
77
|
-
if (working === false) return null;
|
|
78
|
-
|
|
79
|
-
clearTimeout(timeout);
|
|
80
|
-
multi.destroy();
|
|
81
|
-
working = false;
|
|
82
|
-
progress.forEach((p, i) => {
|
|
83
|
-
delete progress[i];
|
|
84
|
-
delete barNames[i];
|
|
85
|
-
});
|
|
86
|
-
delete this;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
package/example/single.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
2
|
+
|
|
3
|
+
const multi = multimeter(process);
|
|
4
|
+
|
|
5
|
+
multi.drop((bar) => {
|
|
6
|
+
const iv = setInterval(() => {
|
|
7
|
+
const p = bar.percent();
|
|
8
|
+
bar.percent(p + 1 / 100);
|
|
3
9
|
|
|
4
|
-
multi.drop(function (bar) {
|
|
5
|
-
var iv = setInterval(function () {
|
|
6
|
-
var p = bar.percent();
|
|
7
|
-
bar.percent(p + 1/100);
|
|
8
|
-
|
|
9
10
|
if (p >= 1) clearInterval(iv);
|
|
10
11
|
}, 25);
|
|
11
12
|
});
|
package/example/sum.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const multi = multimeter(process);
|
|
4
|
+
const charm = multi.charm;
|
|
5
5
|
charm.on('^C', process.exit);
|
|
6
6
|
charm.reset();
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
for (
|
|
8
|
+
const xs = [];
|
|
9
|
+
for (let i = 0; i < 100; i++) xs.push(i);
|
|
10
10
|
|
|
11
11
|
console.log('Calculating the sum of [0..100]:\n');
|
|
12
12
|
charm.write(' ');
|
|
13
13
|
|
|
14
|
-
multi.drop(
|
|
14
|
+
multi.drop((bar) => {
|
|
15
15
|
bar.percent(0);
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
charm.write('\n\nResult: ');
|
|
18
|
-
charm.position(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
charm.position((x, y) => {
|
|
19
|
+
let sum = 0;
|
|
20
|
+
const iv = setInterval(() => {
|
|
21
21
|
sum += xs.shift();
|
|
22
|
-
|
|
23
|
-
bar.percent(1 - xs.length/100);
|
|
24
|
-
|
|
22
|
+
|
|
23
|
+
bar.percent(1 - xs.length / 100);
|
|
24
|
+
|
|
25
25
|
charm
|
|
26
26
|
.position(x, y)
|
|
27
27
|
.erase('end')
|
|
28
28
|
.write(sum.toString())
|
|
29
29
|
;
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
if (xs.length === 0) {
|
|
32
32
|
clearInterval(iv);
|
|
33
33
|
multi.destroy();
|
package/example/web_multibar.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import multimeter from 'setitch-multimeter';
|
|
3
3
|
|
|
4
|
-
http.createServer(
|
|
4
|
+
http.createServer((req, res) => {
|
|
5
5
|
res.setHeader('content-type', 'application/octet-stream');
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
const multi = multimeter(res);
|
|
8
8
|
multi.charm.on('^C', process.exit);
|
|
9
9
|
multi.charm.reset();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
const bars = [];
|
|
12
|
+
const progress = [];
|
|
13
|
+
const deltas = [];
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < 5; i++) {
|
|
16
|
+
const s = 'ABCDE'[i] + ': \n';
|
|
17
17
|
multi.write(s);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
width
|
|
21
|
-
solid
|
|
22
|
-
text
|
|
23
|
-
foreground
|
|
24
|
-
background
|
|
18
|
+
|
|
19
|
+
const bar = multi(s.length, i + 1, {
|
|
20
|
+
width: 20,
|
|
21
|
+
solid: {
|
|
22
|
+
text: '|',
|
|
23
|
+
foreground: 'white',
|
|
24
|
+
background: 'blue'
|
|
25
25
|
},
|
|
26
|
-
empty
|
|
26
|
+
empty: { text: ' ' },
|
|
27
27
|
});
|
|
28
28
|
bars.push(bar);
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
deltas[i] = 1 + Math.random() * 9;
|
|
31
31
|
progress.push(0);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
multi.write('\nbeep boop\n');
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
progress.forEach(
|
|
35
|
+
|
|
36
|
+
let pending = progress.length;
|
|
37
|
+
const iv = setInterval(() => {
|
|
38
|
+
progress.forEach((p, i) => {
|
|
39
39
|
progress[i] += Math.random() * deltas[i];
|
|
40
|
-
bars[i].percent(progress[i]/100);
|
|
41
|
-
if (p < 100 && progress[i] >= 100) pending
|
|
40
|
+
bars[i].percent(progress[i] / 100);
|
|
41
|
+
if (p < 100 && progress[i] >= 100) pending--;
|
|
42
42
|
if (pending === 0) {
|
|
43
43
|
multi.write('\nAll done.\n');
|
|
44
44
|
res.end();
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}, 100);
|
|
48
|
-
|
|
49
|
-
res.connection.on('end',
|
|
48
|
+
|
|
49
|
+
res.connection.on('end', () => {
|
|
50
50
|
multi.destroy();
|
|
51
51
|
clearInterval(iv);
|
|
52
52
|
});
|
package/example/web_multirel.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import multimeter from 'setitch-multimeter';
|
|
3
3
|
|
|
4
|
-
http.createServer(
|
|
4
|
+
http.createServer((req, res) => {
|
|
5
5
|
res.setHeader('content-type', 'application/octet-stream');
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
const multi = multimeter(res);
|
|
8
8
|
multi.charm.on('^C', process.exit);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (
|
|
15
|
-
|
|
9
|
+
|
|
10
|
+
const bars = [];
|
|
11
|
+
const progress = [];
|
|
12
|
+
const deltas = [];
|
|
13
|
+
|
|
14
|
+
for (let i = 0; i < 5; i++) {
|
|
15
|
+
const s = 'ABCDE'[i] + ': \n';
|
|
16
16
|
multi.write(s);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
width
|
|
20
|
-
solid
|
|
21
|
-
text
|
|
22
|
-
foreground
|
|
23
|
-
background
|
|
17
|
+
|
|
18
|
+
const bar = multi.rel(4, i, {
|
|
19
|
+
width: 20,
|
|
20
|
+
solid: {
|
|
21
|
+
text: '|',
|
|
22
|
+
foreground: 'white',
|
|
23
|
+
background: 'blue'
|
|
24
24
|
},
|
|
25
|
-
empty
|
|
25
|
+
empty: { text: ' ' },
|
|
26
26
|
});
|
|
27
27
|
bars.push(bar);
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
deltas[i] = 5 + Math.random() * 10;
|
|
30
30
|
progress.push(0);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
multi.offset += 2;
|
|
34
34
|
multi.write('\nbeep');
|
|
35
|
-
|
|
36
|
-
setTimeout(
|
|
37
|
-
multi.offset
|
|
35
|
+
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
multi.offset++;
|
|
38
38
|
multi.write('\n boop');
|
|
39
39
|
}, 1000);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
progress.forEach(
|
|
40
|
+
|
|
41
|
+
let pending = progress.length;
|
|
42
|
+
const iv = setInterval(() => {
|
|
43
|
+
progress.forEach((p, i) => {
|
|
44
44
|
progress[i] += Math.random() * deltas[i];
|
|
45
|
-
bars[i].percent(progress[i]/100);
|
|
46
|
-
if (p < 100 && progress[i] >= 100) pending
|
|
45
|
+
bars[i].percent(progress[i] / 100);
|
|
46
|
+
if (p < 100 && progress[i] >= 100) pending--;
|
|
47
47
|
if (pending === 0) {
|
|
48
48
|
multi.write('\nAll done.\n');
|
|
49
49
|
res.end();
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}, 100);
|
|
53
|
-
|
|
54
|
-
res.connection.on('end',
|
|
53
|
+
|
|
54
|
+
res.connection.on('end', () => {
|
|
55
55
|
multi.destroy();
|
|
56
56
|
clearInterval(iv);
|
|
57
57
|
});
|
package/example/web_sum.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
http.createServer(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
for (
|
|
10
|
-
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import multimeter from 'setitch-multimeter';
|
|
3
|
+
|
|
4
|
+
http.createServer((req, res) => {
|
|
5
|
+
const multi = multimeter(res);
|
|
6
|
+
const charm = multi.charm;
|
|
7
|
+
|
|
8
|
+
const xs = [];
|
|
9
|
+
for (let i = 0; i < 100; i++) xs.push(i);
|
|
10
|
+
|
|
11
11
|
charm.reset()
|
|
12
12
|
.write('Calculating the sum of [0..100]:\n\n')
|
|
13
13
|
;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
const bar = multi(4, 3, { width: 20 });
|
|
16
16
|
bar.percent(0);
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
let sum = 0;
|
|
19
19
|
charm.write('\n\nResult: ' + sum);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
bar.percent(1 - xs.length/100);
|
|
24
|
-
|
|
20
|
+
|
|
21
|
+
const iv = setInterval(() => {
|
|
22
|
+
const x = xs.shift();
|
|
23
|
+
bar.percent(1 - xs.length / 100);
|
|
24
|
+
|
|
25
25
|
charm
|
|
26
26
|
.left(sum.toString().length)
|
|
27
27
|
.erase('end')
|
|
28
28
|
;
|
|
29
29
|
sum += x;
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
charm.write(sum.toString());
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
if (xs.length === 0) {
|
|
34
34
|
charm.write('\n');
|
|
35
35
|
res.end();
|
|
36
36
|
}
|
|
37
37
|
}, 50);
|
|
38
|
-
|
|
39
|
-
res.connection.on('end',
|
|
38
|
+
|
|
39
|
+
res.connection.on('end', () => {
|
|
40
40
|
multi.destroy();
|
|
41
41
|
clearInterval(iv);
|
|
42
42
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "setitch-multimeter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "render multiple progress bars at once on the terminal",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": "./src/index.js",
|
|
6
8
|
"directories": {
|
|
7
9
|
"lib": ".",
|
|
8
10
|
"example": "example",
|
|
9
11
|
"test": "test"
|
|
10
12
|
},
|
|
11
13
|
"dependencies": {
|
|
12
|
-
"charm": "
|
|
14
|
+
"charm": "1.0.2"
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
15
17
|
"type": "git",
|
|
@@ -37,7 +39,8 @@
|
|
|
37
39
|
}
|
|
38
40
|
],
|
|
39
41
|
"license": "MIT/X11",
|
|
40
|
-
"
|
|
41
|
-
"node": ">=
|
|
42
|
-
}
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "npm@11.13.0"
|
|
43
46
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import charmer from 'charm';
|
|
2
|
+
import Bar from './lib/bar.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @return {number|(function(*, *, {}=): Bar)}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default function multimeter(...args) {
|
|
9
|
+
const c = args[0];
|
|
10
|
+
let charm;
|
|
11
|
+
|
|
12
|
+
if (c instanceof charmer.Charm) {
|
|
13
|
+
charm = c;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
charm = charmer(...args);
|
|
17
|
+
charm.on('^C', () => {
|
|
18
|
+
charm.destroy();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const multi = (x, y, params = {}) => {
|
|
23
|
+
if (typeof x === 'object') {
|
|
24
|
+
params = x;
|
|
25
|
+
x = params.x;
|
|
26
|
+
y = params.y;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (x === undefined) x = '+0';
|
|
30
|
+
if (y === undefined) y = '+0';
|
|
31
|
+
|
|
32
|
+
const bar = new Bar(charm, x, y, params);
|
|
33
|
+
|
|
34
|
+
multi.bars.push(bar);
|
|
35
|
+
bar.offset = multi.offset;
|
|
36
|
+
multi.on('offset', (o) => {
|
|
37
|
+
bar.offset = o;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return bar;
|
|
41
|
+
};
|
|
42
|
+
multi.bars = [];
|
|
43
|
+
|
|
44
|
+
multi.rel = (x, y, params) => {
|
|
45
|
+
return multi(x, '-' + y, params);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
multi.drop = (params, cb) => {
|
|
49
|
+
if (!cb) {
|
|
50
|
+
cb = params;
|
|
51
|
+
params = {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
charm.position((x, y) => {
|
|
55
|
+
const bar = new Bar(charm, x, y, params);
|
|
56
|
+
multi.bars.push(bar);
|
|
57
|
+
multi.on('offset', (o) => {
|
|
58
|
+
bar.offset = o;
|
|
59
|
+
});
|
|
60
|
+
cb(bar);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
multi.charm = charm;
|
|
65
|
+
multi.destroy = charm.destroy.bind(charm);
|
|
66
|
+
|
|
67
|
+
multi.on = charm.on.bind(charm);
|
|
68
|
+
multi.emit = charm.emit.bind(charm);
|
|
69
|
+
multi.removeListener = charm.removeListener.bind(charm);
|
|
70
|
+
multi.write = charm.write.bind(charm);
|
|
71
|
+
|
|
72
|
+
let offset = 0;
|
|
73
|
+
Object.defineProperty(multi, 'offset', {
|
|
74
|
+
set(o) {
|
|
75
|
+
offset = o;
|
|
76
|
+
multi.emit('offset', o);
|
|
77
|
+
},
|
|
78
|
+
get() {
|
|
79
|
+
return offset;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return multi;
|
|
84
|
+
}
|
package/src/lib/bar.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export default class Bar {
|
|
2
|
+
constructor(charm, x, y, params) {
|
|
3
|
+
this.charm = charm;
|
|
4
|
+
this.x = x;
|
|
5
|
+
this.y = y;
|
|
6
|
+
this.width = params.width || 10;
|
|
7
|
+
this.offset = params.offset || 0;
|
|
8
|
+
|
|
9
|
+
this.before = params.before || '[';
|
|
10
|
+
this.after = params.after || '] ';
|
|
11
|
+
|
|
12
|
+
this.solid = params.solid || {
|
|
13
|
+
background: 'blue',
|
|
14
|
+
foreground: 'white',
|
|
15
|
+
text: '|'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
this.empty = params.empty || {
|
|
19
|
+
background: null,
|
|
20
|
+
foreground: null,
|
|
21
|
+
text: ' '
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.text = params.text || {
|
|
25
|
+
background: null,
|
|
26
|
+
foreground: null,
|
|
27
|
+
text: ''
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.progress = {
|
|
31
|
+
percent: 0,
|
|
32
|
+
ratio: 0
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
draw(bars, msg) {
|
|
37
|
+
bars = Math.floor(bars);
|
|
38
|
+
this.charm.push(true);
|
|
39
|
+
|
|
40
|
+
if (this.y.toString().match(/^[+-]/)) {
|
|
41
|
+
if (this.y.toString().match(/^-/)) {
|
|
42
|
+
this.charm.up(-this.y + this.offset);
|
|
43
|
+
}
|
|
44
|
+
else if (this.y.toString().match(/^\+/)) {
|
|
45
|
+
this.charm.down(+this.y - this.offset);
|
|
46
|
+
}
|
|
47
|
+
this.charm.column(+this.x);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.charm.position(this.x, this.y);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.charm.write(this.before);
|
|
54
|
+
|
|
55
|
+
if (this.solid.background) {
|
|
56
|
+
this.charm.background(this.solid.background);
|
|
57
|
+
}
|
|
58
|
+
if (this.solid.foreground) {
|
|
59
|
+
this.charm.foreground(this.solid.foreground);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.charm
|
|
63
|
+
.write(Array(bars + 1).join(this.solid.text))
|
|
64
|
+
.display('reset')
|
|
65
|
+
;
|
|
66
|
+
|
|
67
|
+
if (this.empty.background) {
|
|
68
|
+
this.charm.background(this.empty.background);
|
|
69
|
+
}
|
|
70
|
+
if (this.empty.foreground) {
|
|
71
|
+
this.charm.foreground(this.empty.foreground);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.charm
|
|
75
|
+
.write(Array(this.width - bars + 1).join(this.empty.text))
|
|
76
|
+
;
|
|
77
|
+
|
|
78
|
+
if (this.text.background) {
|
|
79
|
+
this.charm.background(this.text.background);
|
|
80
|
+
}
|
|
81
|
+
if (this.text.foreground) {
|
|
82
|
+
this.charm.foreground(this.text.foreground);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.charm.write(this.after + msg);
|
|
86
|
+
|
|
87
|
+
this.charm.pop(true);
|
|
88
|
+
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
percent(p, msg) {
|
|
93
|
+
if (p === undefined) {
|
|
94
|
+
return this.progress.percent;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
p = Math.max(Math.min(1, p), 0);
|
|
98
|
+
this.progress.percent = p;
|
|
99
|
+
this.progress.ratio = [p, 100];
|
|
100
|
+
|
|
101
|
+
let pp = Math.round(p * 10000, 2) / 100;
|
|
102
|
+
if (p >= 1) pp = ' 100.00';
|
|
103
|
+
if (p < 1) pp = ' ' + pp;
|
|
104
|
+
|
|
105
|
+
this.draw(
|
|
106
|
+
this.width * p,
|
|
107
|
+
msg || (pp + ' % ')
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
ratio(n, d, msg) {
|
|
114
|
+
if (n === undefined && d === undefined) {
|
|
115
|
+
return this.progress.ratio;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const f = n / d;
|
|
119
|
+
this.progress.ratio = [n, d];
|
|
120
|
+
this.progress.percent = f * 100;
|
|
121
|
+
|
|
122
|
+
this.draw(
|
|
123
|
+
this.width * f,
|
|
124
|
+
msg || (n + ' / ' + d)
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import multimeter from 'setitch-multimeter';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param barNames Array of bar names
|
|
5
|
+
* @param makeEven boolean (false) should bar start evenly (from longest bar label/name
|
|
6
|
+
* @returns API: {writeText, updateProgress, close}
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
export default function ProgressBar(barNames = [], makeEven = true) {
|
|
10
|
+
const multi = multimeter(process);
|
|
11
|
+
|
|
12
|
+
const bars = [];
|
|
13
|
+
const progress = [];
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < barNames.length; i++) {
|
|
16
|
+
const s = barNames[i] + ': \n';
|
|
17
|
+
multi.write(s);
|
|
18
|
+
|
|
19
|
+
const offset = makeEven
|
|
20
|
+
? barNames.reduce((a, b) => (a.length > b.length ? a : b), '').length + 3
|
|
21
|
+
: barNames[barNames.length - 1 - i].length + 3;
|
|
22
|
+
|
|
23
|
+
const bar = multi.rel(offset, i, {
|
|
24
|
+
width: 80,
|
|
25
|
+
solid: {
|
|
26
|
+
text: '#',
|
|
27
|
+
foreground: 'white',
|
|
28
|
+
// background : 'blue'
|
|
29
|
+
},
|
|
30
|
+
empty: { text: '|' },
|
|
31
|
+
});
|
|
32
|
+
bars.push(bar);
|
|
33
|
+
progress.push(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
multi.offset = 1;
|
|
37
|
+
let lastString = '';
|
|
38
|
+
let lastUsedString = '';
|
|
39
|
+
let working = true;
|
|
40
|
+
let timeout;
|
|
41
|
+
|
|
42
|
+
function update() {
|
|
43
|
+
if (working === false) return;
|
|
44
|
+
const k = new Array(lastUsedString.length).join(' ');
|
|
45
|
+
multi.write(k);
|
|
46
|
+
multi.write(lastString);
|
|
47
|
+
lastUsedString = lastString;
|
|
48
|
+
lastString = '';
|
|
49
|
+
|
|
50
|
+
bars.forEach((bar, i) => {
|
|
51
|
+
bar.percent(progress[i]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
timeout = setTimeout(update, 100);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
timeout = setTimeout(update, 100);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
writeText(text) {
|
|
61
|
+
if (working === false) return null;
|
|
62
|
+
|
|
63
|
+
lastString = text;
|
|
64
|
+
|
|
65
|
+
return this;
|
|
66
|
+
},
|
|
67
|
+
updateProgress(name, percentage) {
|
|
68
|
+
if (working === false) return null;
|
|
69
|
+
|
|
70
|
+
const index = barNames.indexOf(name);
|
|
71
|
+
if (index === -1) return -1;
|
|
72
|
+
|
|
73
|
+
percentage = Math.round(percentage * 10000) / 10000;
|
|
74
|
+
|
|
75
|
+
progress[progress.length - 1 - index] = percentage;
|
|
76
|
+
if (percentage === 1) setTimeout(update);
|
|
77
|
+
return this;
|
|
78
|
+
},
|
|
79
|
+
close() {
|
|
80
|
+
if (working === false) return null;
|
|
81
|
+
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
multi.destroy();
|
|
84
|
+
working = false;
|
|
85
|
+
progress.forEach((p, i) => {
|
|
86
|
+
delete progress[i];
|
|
87
|
+
delete barNames[i];
|
|
88
|
+
});
|
|
89
|
+
delete this;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
package/index.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var charmer = require('charm');
|
|
2
|
-
var Bar = require('./lib/bar');
|
|
3
|
-
|
|
4
|
-
var exports = module.exports = function (c) {
|
|
5
|
-
if (c instanceof charmer.Charm) {
|
|
6
|
-
var charm = c;
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
var charm = charmer.apply(null, arguments);
|
|
10
|
-
charm.on('^C', function () {
|
|
11
|
-
charm.destroy();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
var multi = function (x, y, params) {
|
|
16
|
-
if (typeof x === 'object') {
|
|
17
|
-
params = x;
|
|
18
|
-
x = params.x;
|
|
19
|
-
y = params.y;
|
|
20
|
-
}
|
|
21
|
-
if (!params) params = {};
|
|
22
|
-
|
|
23
|
-
if (x === undefined) x = '+0';
|
|
24
|
-
if (y === undefined) y = '+0';
|
|
25
|
-
|
|
26
|
-
var bar = new Bar(charm, x, y, params);
|
|
27
|
-
multi.bars.push(bar);
|
|
28
|
-
bar.offset = multi.offset;
|
|
29
|
-
multi.on('offset', function (o) {
|
|
30
|
-
bar.offset = o;
|
|
31
|
-
});
|
|
32
|
-
return bar;
|
|
33
|
-
};
|
|
34
|
-
multi.bars = [];
|
|
35
|
-
|
|
36
|
-
multi.rel = function (x, y, params) {
|
|
37
|
-
return multi(x, '-' + y, params);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
multi.drop = function (params, cb) {
|
|
41
|
-
if (!cb) { cb = params; params = {} }
|
|
42
|
-
|
|
43
|
-
charm.position(function (x, y) {
|
|
44
|
-
var bar = new Bar(charm, x, y, params);
|
|
45
|
-
multi.bars.push(bar);
|
|
46
|
-
multi.on('offset', function (o) {
|
|
47
|
-
bar.offset = o;
|
|
48
|
-
});
|
|
49
|
-
cb(bar);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
multi.charm = charm;
|
|
54
|
-
multi.destroy = charm.destroy.bind(charm);
|
|
55
|
-
|
|
56
|
-
multi.on = charm.on.bind(charm);
|
|
57
|
-
multi.emit = charm.emit.bind(charm);
|
|
58
|
-
multi.removeListener = charm.removeListener.bind(charm);
|
|
59
|
-
multi.write = charm.write.bind(charm);
|
|
60
|
-
|
|
61
|
-
(function () {
|
|
62
|
-
var offset = 0;
|
|
63
|
-
Object.defineProperty(multi, 'offset', {
|
|
64
|
-
set : function (o) {
|
|
65
|
-
offset = o;
|
|
66
|
-
multi.emit('offset', o);
|
|
67
|
-
},
|
|
68
|
-
get : function () {
|
|
69
|
-
return offset;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
})();
|
|
73
|
-
|
|
74
|
-
return multi;
|
|
75
|
-
};
|
package/lib/bar.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
var Bar = module.exports = function (charm, x, y, params) {
|
|
2
|
-
this.charm = charm;
|
|
3
|
-
this.x = x;
|
|
4
|
-
this.y = y;
|
|
5
|
-
this.width = params.width || 10;
|
|
6
|
-
this.offset = params.offset || 0;
|
|
7
|
-
|
|
8
|
-
this.before = params.before || '[';
|
|
9
|
-
this.after = params.after || '] ';
|
|
10
|
-
|
|
11
|
-
this.solid = params.solid || {
|
|
12
|
-
background : 'blue',
|
|
13
|
-
foreground : 'white',
|
|
14
|
-
text : '|'
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
this.empty = params.empty || {
|
|
18
|
-
background : null,
|
|
19
|
-
foreground : null,
|
|
20
|
-
text : ' '
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this.progress = {
|
|
24
|
-
percent : 0,
|
|
25
|
-
ratio : 0
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Bar.prototype.draw = function (bars, msg) {
|
|
30
|
-
bars = Math.floor(bars);
|
|
31
|
-
this.charm.push(true);
|
|
32
|
-
|
|
33
|
-
if (this.y.toString().match(/^[+-]/)) {
|
|
34
|
-
if (this.y.toString().match(/^-/)) {
|
|
35
|
-
this.charm.up(-this.y + this.offset);
|
|
36
|
-
}
|
|
37
|
-
else if (this.y.toString().match(/^\+/)) {
|
|
38
|
-
this.charm.down(+this.y - this.offset);
|
|
39
|
-
}
|
|
40
|
-
this.charm.column(+this.x);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.charm.position(this.x, this.y);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.charm.write(this.before);
|
|
47
|
-
|
|
48
|
-
if (this.solid.background) {
|
|
49
|
-
this.charm.background(this.solid.background);
|
|
50
|
-
}
|
|
51
|
-
if (this.solid.foreground) {
|
|
52
|
-
this.charm.foreground(this.solid.foreground);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.charm
|
|
56
|
-
.write(Array(bars + 1).join(this.solid.text))
|
|
57
|
-
.display('reset')
|
|
58
|
-
;
|
|
59
|
-
|
|
60
|
-
if (this.empty.background) {
|
|
61
|
-
this.charm.background(this.empty.background);
|
|
62
|
-
}
|
|
63
|
-
if (this.empty.foreground) {
|
|
64
|
-
this.charm.foreground(this.empty.foreground);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.charm
|
|
68
|
-
.write(Array(this.width - bars + 1).join(this.empty.text))
|
|
69
|
-
.write(this.after + msg)
|
|
70
|
-
;
|
|
71
|
-
|
|
72
|
-
this.charm.pop(true);
|
|
73
|
-
|
|
74
|
-
return this;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
Bar.prototype.percent = function (p, msg) {
|
|
78
|
-
if (p === undefined) {
|
|
79
|
-
return this.progress.percent;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
p = Math.max(Math.min(1, p), 0);
|
|
83
|
-
this.progress.percent = p;
|
|
84
|
-
this.progress.ratio = [ p, 100 ];
|
|
85
|
-
|
|
86
|
-
let pp = Math.round(p*10000, 2)/100;
|
|
87
|
-
if (p >= 1) pp = ' 100.00';
|
|
88
|
-
if (p < 1) pp = ' ' + pp;
|
|
89
|
-
|
|
90
|
-
this.draw(
|
|
91
|
-
this.width * p,
|
|
92
|
-
msg || (pp + ' % ')
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
return this;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
Bar.prototype.ratio = function (n, d, msg) {
|
|
99
|
-
if (n === undefined && d === undefined) {
|
|
100
|
-
return this.progress.ratio;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var f = n / d;
|
|
104
|
-
this.progress.ratio = [n, d];
|
|
105
|
-
this.progress.percent = f * 100;
|
|
106
|
-
|
|
107
|
-
this.draw(
|
|
108
|
-
this.width * f,
|
|
109
|
-
msg || (n + ' / ' + d)
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
return this;
|
|
113
|
-
};
|