-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathexample-multibar-styling.js
80 lines (67 loc) · 1.91 KB
/
example-multibar-styling.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
const _progress = require('../cli-progress');
const files = {
'eta.js ': 187,
'generic-bar.js': 589,
'multi-bar.js ': 5342,
'options.txt ': 42,
'single-bar.js ': 2123,
'terminal.txt ': 4123
};
const bars = [];
// create new container
const multibar = new _progress.MultiBar({
format: ' {bar} | "{file}" | {value}/{total}',
hideCursor: true,
clearOnComplete: true,
stopOnComplete: true,
noTTYOutput: true
});
console.log("Downloading files..\n");
// total progress
const masterProgress = multibar.create(Object.keys(files).length, 0, {}, {
format: ' {bar} | {value} of {total} files',
barCompleteChar: '>',
barIncompleteChar: ' ',
align: 'center',
autopadding: true
});
// add bars
for (const filename in files){
const size = files[filename];
// txt file ?
if (filename.match(/\.txt\s*$/g) !== null){
// override the format option
bars.push(multibar.create(size, 0, {file: filename}, {
format: ' {bar} | "{file}" | {value}/{total} | textfile',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591'
}));
}else{
bars.push(multibar.create(size, 0, {file: filename}, {
barIncompleteChar: '\u2591'
}));
}
}
const timer = setInterval(function(){
// master status
let completedTasks = 0;
// increment
for (let i=0; i<bars.length;i++){
const bar = bars[i];
// download complete ?
if (bar.value < bar.total){
bar.increment();
}else{
completedTasks++;
}
}
// update master progress
masterProgress.update(completedTasks);
// progress bar running ?
// check "isActive" property in case you've enabled "stopOnComplete" !
if (multibar.isActive === false){
clearInterval(timer);
//multibar.stop();
console.log('Download complete!')
}
}, 3);