cli-progress icon indicating copy to clipboard operation
cli-progress copied to clipboard

Incorrect MultiBar.remove behaviour

Open khokm opened this issue 2 years ago • 2 comments

import cliProgress from "cli-progress";

// create new container
const multibar = new cliProgress.MultiBar(
    {
        clearOnComplete: false,
        hideCursor: true,
        format: " {bar} | {filename} | {value}/{total}",
    },
    cliProgress.Presets.shades_grey
);

const b1 = multibar.create(200, 0);
const b2 = multibar.create(1000, 0);

b1.update(0, { filename: "Task 1 in progress" });
b2.update(0, { filename: "Task 2 in progress" });

setTimeout(() => {
    // Task 1 completed, remove bar.
    multibar.remove(b1);
}, 1000);

Expected behaviour: After 1 second only 'Task 2 in progress' caption should left on screen. Actual behaviour: After 1 second 'Task 1 in progress' caption is still on screen, but 'Task 2 in progress' removed instead.

khokm avatar Sep 02 '23 13:09 khokm

just set clearOnComplete to true

AndiDittrich avatar Sep 09 '23 07:09 AndiDittrich

@AndiDittrich

import cliProgress from "cli-progress";

// create new container
const multibar = new cliProgress.MultiBar(
    {
        clearOnComplete: true,
        hideCursor: true,
        format: " {bar} | {filename} | {value}/{total}",
    },
    cliProgress.Presets.shades_grey
);

const b1 = multibar.create(200, 0, { clearOnComplete: true });
const b2 = multibar.create(1000, 0, { clearOnComplete: true });

b1.update(0, { filename: "Task 1 in progress" });
b2.update(0, { filename: "Task 2 in progress" });

setTimeout(() => {
    // Task 1 completed, remove bar.
    multibar.remove(b1);
}, 1000);

Seems like nothing has changed. Btw i'm using Windows Terminal, if it matters. clearOnComplete clears the screen only when all of the children bars are completed. But in my case i want only one of bars to be removed, not waiting for others to complete. I already fixed this in attached PR. Could you please merge it?

khokm avatar Sep 09 '23 08:09 khokm