Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Show details during a progress #36

Open
ludovic-gasc opened this issue Feb 6, 2012 · 3 comments
Open

Show details during a progress #36

ludovic-gasc opened this issue Feb 6, 2012 · 3 comments

Comments

@ludovic-gasc
Copy link

With the progress module, if you print information about the data in treatment, the progress bar is broken.
Example:

for i in progress.bar(range(100)):
    print(i)
    sleep(random() * 0.2)

It could be useful to add a method to print the current data processed, under the progress bar for example:

for i in progress.bar(range(100)):
    progress.details(i)
    sleep(random() * 0.2)
@jpiper
Copy link
Collaborator

jpiper commented Feb 7, 2012

This would be relatively easy to add, but I'm wondering about the best way to implement it. Do you think there should be a small buffer (n lines under the progress bar), or maybe fill the rest of the terminal window with the puts() statements?

@jpiper
Copy link
Collaborator

jpiper commented Feb 7, 2012

Actually, thinking about it, this would require changing progress.bar (which is currently a function) to be a class. It would have an iterable magic method similar to what it currently has, and other methods for printing to the screen, so would require a big refactor. You'd also have to do your for loops like so instead

newbar = progress.bar()
for i in newbar(range(100)):
    ...

I'll see if I can knock together a proof of principle.

In the mean time, you can use sys.stderr.write() to put stuff before the progress bar;

for i in progress.bar(range(100)):
    sleep(random() * 0.2)
    sys.stderr.write("Progress: \t")

will yield
>>> Progess: [######## ] 27/100 - 00:00:05

but note, this will redraw on every iteration, so is likely only useful for when your iterations are slow (or few)

@ludovic-gasc
Copy link
Author

I don't know, each solution is good, but it could be complicated to implement, couldn't it ?

Maybe the easiest way to implement this, we should only authorize one string without line breaks by iteration, and put the string at the right of the progress bar.
It's enough in the most cases.

Ideally, it could be wonderful to have the three solutions ;-)

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

No branches or pull requests

2 participants