Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render multiple progress bars #7

Closed
shixiaobao17145 opened this issue Dec 2, 2020 · 2 comments
Closed

Render multiple progress bars #7

shixiaobao17145 opened this issue Dec 2, 2020 · 2 comments

Comments

@shixiaobao17145
Copy link

Thanks for making this library.

Sometimes we want to show multiple bars at a time, for example, if we program to download files, we want to show their progress on the console together. How to make that happen with this library? Thanks!

@fuxingZhang
Copy link
Collaborator

Good idea! I need some time to think.

@fuxingZhang
Copy link
Collaborator

fuxingZhang commented Dec 4, 2020

already updated

import { MultiProgressBar } from "https://deno.land/x/progress@v1.2.3/mod.ts";

const title = 'download files';
const total = 100;

const bars = new MultiProgressBar({
  title,
  // clear: true,
  complete: '=',
  incomplete: '-',
  display: '[:bar] :text :percent :time :completed/:total'
});

let completed1 = 0;
let completed2 = 0;

function downloading() {
  if (completed1 <= total || completed2 <= total) {
    completed1 += 1
    completed2 += 2
    bars.render([
      { completed: completed1, total, text: "file1" },
      { completed: completed2, total, text: "file2" }
    ]);

    setTimeout(function () {
      downloading();
    }, 100)
  }
}

downloading();

You can also change the style of the progress bar

    bars.render([
      {
        completed: completed1,
        total,
        text: "file1",
        complete: "*",
        incomplete: ".",
      },
      { completed: completed2, total, text: "file2" },
    ]);

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants