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

Statusbar elapsed time gets erroneously updated even after statusbar is closed #66

Open
guano opened this issue Jun 5, 2024 · 2 comments
Labels

Comments

@guano
Copy link

guano commented Jun 5, 2024

Describe the bug
A statusbar's elapsed field gets updated, even if it is closed and not refreshed.

Looks like this bug was fixed for counters but not statusbars
see issue #62

To Reproduce

import time                                                                                                   
import enlighten                                                                                              
                                                                                                              
enlightenmanager=enlighten.get_manager()                                                                      
                                                                                                              
sb = enlightenmanager.status_bar(                                               
            leave=True, autorefresh=False, color="black_on_green",                                            
            status_format=u"statusbar elapsed:{elapsed}")                                                     
time.sleep(1)                                                                                                 
sb.update()                                                                                                   
time.sleep(1)                                                                                                 
sb.update()                                                                                                   
time.sleep(1)                                                                                                 
sb.update()                                                                                                   
time.sleep(1)                                                                                                 
                                                                                                              
sb.color = "black_on_red"                                                                                     
sb.update()                                                                                                   
sb.close()                                                                                                    
time.sleep(5)                                                                                                 
                                                                                                              
sb2 = enlightenmanager.status_bar(                                                                            
            leave=True, autorefresh=False, color="black_on_green",                                            
            status_format=u"statusbar2 {elapsed}")                                                            
time.sleep(1)                                                                                                 
sb2.close()                                                                                                   
                                                                                                              
enlightenmanager.stop()     

sb's elapsed time gets updated even though it's not being updated and is in fact closed.

Environment (please complete the following infkkkormation):

  • Enlighten Version: commit 91e3999 (master as of May 31, 2024)
  • OS and version: CentOS Linux 7
  • Console application: tmux
  • Special Conditions: -
@avylove
Copy link
Contributor

avylove commented Jun 9, 2024

Thanks for reporting! I left some comments on the PR, but I think the main thing to sort out is when to determine the clock should be stopped for status bars. You went with the closed time which does make sense in some cases, but there could be an argument for the last update in other cases. I'm not sure what the right answer is. I'm leaning towards agreeing with you, but my hesitation is this is different than the way it's handled in progress bars. That may be ok, but I think the "why" needs to be understood and documented.

@guano
Copy link
Author

guano commented Jun 11, 2024

Yeah, it definitely is a decision that can be disputed either way.

In the meantime I have figured out a workaround for my use case at least. The elapsed variable can just be read at close time and inserted as a static string rather than being dynamically updated whenever the manager adds/removes another bar.

from enlighten._util import format_time

# start, sleep, update, etc as in original code sample

sb.update(f"statusbar finished. time elapsed when closed: {format_time(sb.elapsed)}")
sb.close()

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

No branches or pull requests

2 participants