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

Support rate formatters #211

Open
slavafomin opened this issue Jul 20, 2021 · 2 comments
Open

Support rate formatters #211

slavafomin opened this issue Jul 20, 2021 · 2 comments

Comments

@slavafomin
Copy link

slavafomin commented Jul 20, 2021

Hello!

Thank you for this great library!

Right now, library gives no control to how :rate is actually formatted. It's pretty standard use case (it's actually used in the README) when bytes are used for total and tick values. However, the library would output rate in plain bytes, which is absolutely unpractical for end users.

I would suggest to introduce a rate formatter function, e.g.:

import prettyBytes from 'pretty-bytes';

const bar = new ProgressBar('  downloading [:bar] :rate/sec :percent :etas', {
  complete: '=',
  incomplete: ' ',
  width: 20,
  total: totalBytes,
  rateFormat: prettyBytes, // <--- using third-party formatter
});

This will output byte rate in a user-friendly fashion, e.g.: 1.56 MB/sec.

Thanks!

@NathanPB
Copy link

I couldn't really find a solution for this. As the lib seems abandoned, I decided to rewrite it.

If the people reading this in the future want to use it, my version includes this functionality

https://github.com/NathanPB/progress.js

@corwin-of-amber
Copy link

corwin-of-amber commented Jun 24, 2022

This is a gravely needed feature. Every now and then I come across a need to display download progress, and I have to copy & paste some boilerplate to add faux tokens to my progress bar:

data.on('data', (chunk) => {
        let curr = progress.curr + chunk.length;
        progress.tick(chunk.length, {'currM': (curr / 1000000).toFixed(2)})
    })

@NathanPB's version definitely provides an elegant way to specify these formatters and even includes a library of standard formatters. It is a bit more verbose though for the "regular" tokens and also it cannot be used as a drop-in replacement for progress in other contexts.

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

3 participants