Cli -progress软件包 - 如何开始隐藏进度栏?

发布于 2025-01-21 13:31:31 字数 1474 浏览 4 评论 0 原文

我正在使用:
的Cli-progress软件包 https://www.npmjs.com/package/package/cli-progress

这是我根据文档示例的实现:

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);

呈现:

“在此处输入图像描述”

我有两个问题:

  • 为什么有两个酒吧(我想摆脱它第一个)?
  • 为什么从未调用计时器函数(递归称为但没有第一次调用),为什么它可以工作?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文