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

Feature proposal - indeterminable progress bar (unknown total) #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lbeschastny
Copy link

In some situations you may not know the total number of ticks, but want some progress reporting nonetheless.

Right now I have two particular use-cases in mind, but I'm sure there are more:

  1. HTTP downloading with unset content-length header.
  2. Parsing data feed of some unknown length.

Here is how I solved this problem in my clj-progress module (node-progress port to Clojure):

(with-progress-bar " [:wheel][:bar] :done/:total :elapseds :percent :etas"
  (init -1) ; non-positive total
  (...); some code calling (tick)
  (done))

progress

It will be very nice to have something like that in node-progress as well.

If you'll approve my proposal, then I could try to implement it myself based on my previous Clojure implementation, and send you a PR. Though I'm not sure when I'll manage to find some time to do it.

@thebigredgeek
Copy link
Collaborator

Happy to review a PR!

this.total = options.total;
this.width = options.width || this.total;
this.width = options.width || (this.total > 0 ? this.total : Infinity);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if Infinity is a good default here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my proposal this.total could be non-positive, but we can't use non-positive value as a default for width.

So, we need a sane default value. Infinity here means that progress bar will attempt to use all available space.

@lbeschastny
Copy link
Author

Attached my PR with proposed implementation and usage example.

@thebigredgeek
Copy link
Collaborator

Code is out of date. Needs to be updated before considered @lbeschastny

Changes:
 * new `.done()` method to complete the progress
 * new `.updates` counter to track `.render()` calls
 * support for non-positive `.total`
 * no more `.tick()` calls after progress bar is complete and terminated
@lbeschastny
Copy link
Author

lbeschastny commented Dec 18, 2016

@thebigredgeek rebased my branch onto the latest master.

@mctep
Copy link

mctep commented Apr 9, 2017

Hi! Thank you for your job!
This feature is great. I would be glad to use this in my project.

@jainanshul
Copy link

This is a very helpful feature and wondering if this could actually be made available officially via this package.

@jwhitmarsh
Copy link

Any update on this? Any help required?

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

Successfully merging this pull request may close these issues.

None yet

5 participants