npkgz / cli-progress

:hourglass: easy to use progress-bar for command-line/terminal applications
https://www.npmjs.com/package/cli-progress
MIT License
1.11k stars 84 forks source link

Set stopTime to null on start otherwise duration will not work #110

Closed abrown28 closed 3 years ago

abrown28 commented 3 years ago

Duration was not working for me. I fixed it by setting stopTime to null.

abrown28 commented 3 years ago

well it works the first time I go through a start, update, and stop cycle but the next time it's still set to the old stopTime. I guess creating a new progress bar instead of reusing the old one would probably fix it for me.

AndiDittrich commented 3 years ago

Hi @abrown28

thanks for your contribution but your code doesn't make any sense since stopTime is already set in the next loc

abrown28 commented 3 years ago

I'm probably not using it in the way you want but here is some example code

const progress = require("cli-progress")

async function test() { 
  const progressBar = new progress.SingleBar({
    format: '{message} | {bar} | {percentage}% || {value}/{total} records || {duration} || {duration_formatted} || {eta_formatted}',
  }, progress.Presets.shades_classic);

  for(let i=0; i<10; ++i) {
    progressBar.start(100, 0, {
      message: "Testing progress bar when reused"
    })

    for(let j=0; j<100; ++j) {
      progressBar.update(j+1)
      await sleep(1)
    }

    progressBar.stop();
  }
}

async function sleep(seconds) {
  return new Promise(resolve => setTimeout(resolve, seconds*100));
}

test()

When I run the above I get the following:

Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 11 || 11s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s

The duration and duration_formatted only worked the first time. That's what I'm seeing when I pull it with npm

AndiDittrich commented 3 years ago

the fix has already been provided in https://github.com/npkgz/cli-progress/pull/101 but it's not release yet

AndiDittrich commented 3 years ago

v3.9.1 is out including the changes within master (patch #101 )

abrown28 commented 3 years ago

ah gotcha. I missed that :)

Thanks

On Wed, Sep 15, 2021 at 4:20 AM Andi Dittrich @.***> wrote:

v3.9.1 is out including the changes within master (patch #101 https://github.com/npkgz/cli-progress/pull/101 )

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/npkgz/cli-progress/pull/110#issuecomment-919849125, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAUEQQ7YTT2U5LXCKJL3ODUCBQNFANCNFSM5D5YSO6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--


Alex Brown @.***