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

Dynamically change color of status bar #56

Closed Dauriel closed 1 year ago

Dauriel commented 1 year ago

Is your feature request related to a problem? Please describe. Would be nice to have a color input in the update function of the status bar to change the color dynamically.

Describe alternatives you've considered Recreating the color bar instead of updating it does the trick, yet it seems impractical.

Additional context I am not sure if this is already possible or if there's a workaround. I also have not seen it anywhere in the documentation. Sorry if I missed it.

avylove commented 1 year ago

It's not documented specifically, but you can change the color attribute for the counter. It does the same validation for the color that's done when you originally set it. Will you change the color once or twice or many times during the program's runtime?

import time
import enlighten

counter = enlighten.Counter(total=100, desc='Example', unit='ticks', color='red')
for num in range(100):
    time.sleep(0.05)  # Simulate work
    if num == 50:
        counter.color = 'blue'
    counter.update()
Dauriel commented 1 year ago

Oh sweet! Thanks for the quick reply.

I do plan on changing the color many times during the runtime. Do you think that could constitute an issue?

avylove commented 1 year ago

There's a small overhead in validating the color. I don't think you'll notice it, but I could probably move it to it's own method and make it caching so it can be skipped, but I wouldn't worry about it for now.

Dauriel commented 1 year ago

Hm ye that might be a problem. I'd be changing color quite a bit. I'll run some tests and then decide, thanks!

avylove commented 1 year ago

Color resolution caching added in 1.12.0