deno-library / progress

ProgressBar in terminal for deno

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to show ETA

qgustavor opened this issue · comments

Many Node libraries handle ETA, so it looks like a feature that's desired in a library like this. I know calculating ETAs is not simple nor straightforward, but then lets check how Node libraries handle that to get an idea:

I don't know what would be "the Deno philosophy way to implement it". Use a fixed implementation like the above libraries? Leave it for the user? Use a simple implementation but allow the user to configure a custom ETA algorithm? The application I'm using this library works at a constant speed, so for me a linear regression would be fine, but I also worked with applications that had large variations in speed so I had to use a better ETA estimation algorithm for them.

There was no issue about ETA in this repository yet, I don't know what's the position of the contributors on that. If you think that's out of scope and the proper way to adding a ETA is calculating it outside the library then displaying by modifying the title, I'm fine with that too.

commented

landed at https://github.com/deno-library/progress/releases/tag/v1.2.6

example

import ProgressBar from "https://deno.land/x/progress@v1.2.6/mod.ts";

const total = 100;

const progress = new ProgressBar({
  total,
  // here ==>
  // display: ":bar :eta",
  // display: ":bar :percent :time :eta",
  display: ":bar :percent elapsed :time eta :eta",
  // <== here
});

let completed = 0;

function run() {
  if (completed <= total) {
    progress.render(completed++);

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

run();

If you have a good idea, welcome to submit a pull request.

I have been using this feature for the last days and it's working fine. Thanks for implementing it!