MCPcopy Create free account
hub / github.com/npkgz/cli-progress / Example5

Function Example5

examples/example-visual.js:4–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2const _colors = require('ansi-colors');
3
4function Example5(){
5 console.log('');
6 // create new progress bar
7 const b1 = new _progress.Bar({
8 format: 'CLI Progress |' + _colors.cyan('{bar}') + '| {percentage}% || {value}/{total} Chunks || Speed: {speed}',
9 barCompleteChar: '\u2588',
10 barIncompleteChar: '\u2591',
11 hideCursor: true
12 });
13
14 // initialize the bar - defining payload token "speed" with the default value "N/A"
15 b1.start(200, 0, {
16 speed: "N/A"
17 });
18
19 // the bar value - will be linear incremented
20 let value = 0;
21
22 const speedData = [];
23
24 // 20ms update rate
25 const timer = setInterval(function(){
26 // increment value
27 value++;
28
29 // example speed data
30 speedData.push(Math.random()*2+5);
31 const currentSpeedData = speedData.splice(-10);
32
33 // update the bar value
34 b1.update(value, {
35 speed: (currentSpeedData.reduce(function(a, b) { return a + b; }, 0) / currentSpeedData.length).toFixed(2) + "Mb/s"
36 });
37
38 // set limit
39 if (value >= b1.getTotal()){
40 // stop timer
41 clearInterval(timer);
42
43 b1.stop();
44 }
45 }, 20);
46}
47
48Example5();

Callers 1

example-visual.jsFile · 0.70

Calls 5

logMethod · 0.80
getTotalMethod · 0.80
startMethod · 0.45
updateMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…