Rockhopper-Technologies / enlighten

Enlighten Progress Bar for Python Console Apps
https://python-enlighten.readthedocs.io
Mozilla Public License 2.0
416 stars 25 forks source link

Progress bar moving back and forth with a sub counter #69

Open vflaux opened 3 months ago

vflaux commented 3 months ago

Describe the bug The progress bar moves back and forth when incrementing a counter with a sub counter > 0, instead of smoothly going forward.

To Reproduce

#!/usr/bin/env python3
import time
import enlighten

m = enlighten.get_manager()
c: enlighten.Counter = m.counter(total=500)
s = c.add_subcounter("blue3")
s.update(incr=200)
while c.count < c.total:
    c.update(force=True)
    time.sleep(0.05)
c.close()

Environment (please complete the following information):

avylove commented 3 months ago

Thanks for reporting! I'll take a look at your PR. For now you can get closer to what you want using another subcounter.

import time
import enlighten

manager = enlighten.get_manager()
pbar: enlighten.Counter = manager.counter(total=500)
sub2 = pbar.add_subcounter("white")
sub1 = pbar.add_subcounter("blue3")
sub1.update(incr=200)
while pbar.count < pbar.total:
    sub2.update(force=True)
    time.sleep(0.05)
pbar.close()
avylove commented 3 months ago

I'm not sure I'm ok completely getting rid of the remainder logic and I think some corner cases weren't accounted for in your PR. I put something together in #71. Please try it out and see if it works for you.

vflaux commented 2 months ago

71 do fix the issue reported here. The bar progress smoothly without going back.

But the sub counter bar can be inconsistent : going backward & forward even if the count have not changed.

avylove commented 2 months ago

OK, I pushed another change. Now it only rounds when the count matches the total. It's not ideal because it may jump at the end, but it would be weird if the bar wasn't full at the end. Please try it out and let me know what you think.

vflaux commented 2 months ago

That's much better. The sub-counter bar can still progress by one character even if the sub-counter hasn't increased, but at least it never goes back after that.