-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathexample-concurrent-info.js
More file actions
36 lines (28 loc) · 996 Bytes
/
example-concurrent-info.js
File metadata and controls
36 lines (28 loc) · 996 Bytes
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
const cli_progress = require('../cli-progress');
// Generate random file names using random hexadecimal names
const random_file_names = Array(10).fill(0).map(() =>
Math.floor(Math.random() * Math.pow(16, 6)).toString(16) + '.txt'
);
const bar = new cli_progress.Bar({
format: 'Files [{bar}] | {percentage}% | {value}/{total}',
hideCursor: true,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
stopOnComplete: true,
// If clear on complete then both bar and info are cleared
// clearOnComplete: true,
// forceRedraw: true
});
console.log('Downloading files..');
bar.start(200, 0);
const timer = setInterval(() => {
if (bar.value < bar.total) {
bar.increment();
const current_file = random_file_names[Math.floor(bar.value / 20)];
bar.setConcurrentInfo(` --> Downloading ${current_file}...`);
}
if (!bar.isActive) {
clearInterval(timer);
console.log('Download complete!\n');
}
}, 15);