0

I'm using the CLI-Progress package from:
https://www.npmjs.com/package/cli-progress.

This is my implementation according to the documentation example:
https://github.com/npkgz/cli-progress/blob/master/examples/example-visual.js)

const b1 = new progress.Bar({
    format: colors.cyan('[{bar}]') + ' {percentage}% || {value}/{total} Chunks || Speed: {speed}',
    barCompleteChar: '\u2588',
    barIncompleteChar: '\u2591',
    hideCursor: true,
});

b1.start(200, 0, {
    speed: "N/A"
});

let value = 0;
const speedData: number[] = [];

const timer = setInterval(() => {
    value++;
    speedData.push(Math.random() * 2 + 5);
    const currentSpeedData = speedData.splice(-10);
    b1.update(value, {
        speed: (currentSpeedData.reduce((a, b) => {
            return a + b;
        }, 0) / currentSpeedData.length).toFixed(2) + "Mb/s"
    });

    if (value >= b1.getTotal()) {
        clearInterval(timer);
        b1.stop();
    }
}, 20);

Which renders :

enter image description here

I have two questions about this :

  • Why is there two bars (I would like to get rid of the first one) ?
  • Why does it work since the timer function is never called (it is called recursively but there is no first call) ?

Thank you.

Zabon
  • 241
  • 2
  • 18
  • I couldn't reproduce the issue, it worked like charm by adding the following codes: var progress = require('cli-progress'); var colors = require('ansi-colors'); and changed the line speed data declaration line to const speedData = []; – Kenneth Ong Apr 15 '22 at 14:53
  • This is really strange... the only difference is that I'm using import instead of require and Typescript over js... – Zabon Apr 15 '22 at 14:56

0 Answers0