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

Dynamically change color of status bar #56

Closed
Dauriel opened this issue Jun 20, 2023 · 5 comments
Closed

Dynamically change color of status bar #56

Dauriel opened this issue Jun 20, 2023 · 5 comments

Comments

@Dauriel
Copy link

Dauriel commented Jun 20, 2023

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
Copy link
Contributor

avylove commented Jun 20, 2023

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
Copy link
Author

Dauriel commented Jun 20, 2023

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
Copy link
Contributor

avylove commented Jun 21, 2023

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
Copy link
Author

Dauriel commented Jun 21, 2023

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
Copy link
Contributor

avylove commented Sep 24, 2023

Color resolution caching added in 1.12.0

@avylove avylove closed this as completed Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants