-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathexample-logging.js
64 lines (50 loc) · 1.51 KB
/
example-logging.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
const _progress = require('../cli-progress');
const files = {
'eta.js ': 187,
'generic-bar.js': 589,
'multi-bar.js ': 5342,
'options.js ': 42,
'single-bar.js ': 2123,
'terminal.js ': 4123
};
const bars = [];
// create new container
const multibar = new _progress.MultiBar({
format: ' {bar} | "{file}" | {value}/{total}',
hideCursor: true,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
// only the bars will be cleared, not the logged content
clearOnComplete: true,
stopOnComplete: true,
// important! redraw everything to avoid "empty" completed bars
forceRedraw: true
});
console.log("Downloading files..\n");
// add bars
for (const filename in files){
const size = files[filename];
bars.push(multibar.create(size, 0, {file: filename}));
}
const timer = setInterval(function(){
// increment
for (let i=0; i<bars.length;i++){
const bar = bars[i];
// download complete ?
if (bar.value < bar.total){
bar.increment();
}
}
// 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);
let numMessages = 0;
const loggingTimer = setInterval(function(){
// don't forget to add a linebreak !!!
multibar.log(`[${(new Date()).toString()}] I'm logging message #${numMessages++}\n`);
}, 1500);