rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

add situational message to manual_mode, like definite/unknown mode #8

Closed jonturneratduke closed 5 years ago

jonturneratduke commented 5 years ago

trying to add a situational message to the bar in manual mode, with the following code:

    with alive_bar(manual=True) as bar:
        bar("working...")  # <-- crashes here
        bar(1.00)

I get the following error:

File "src/test.py", line 294, in testProgBar
    bar("working...")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/alive_progress/progress.py", line 115, in bar
    run.percent = float(perc)
ValueError: could not convert string to float: 'working...'

It would be valuable to be able to pass a situational message in manual mode.

rogerio-geru commented 5 years ago

Hey @jonturneratduke! Actually it does already support situational messages in manual mode, you just have to pass them both in the bar call. The use in manual mode is: bar(percent, text=None), ie the percent is required, the text is optional.

If there's any demand to pass them separately, ie set the text without changing the current percent, I could change it very quickly to support bar(percent=None, text=None).

jonturneratduke commented 5 years ago

Ah, got it! I guess I should dive into the code and have a look from henceforth. No need to break the individual parameters out in this case -- adding the named param perc did the trick: bar(perc=myProgress, text='working...') I'll slink away and stop being a pest now. :)

rogerio-geru commented 5 years ago

No problem at all!

Yeah, this one you would have noticed for sure... It's in here: https://github.com/rsalmei/alive-progress/blob/master/alive_progress/progress.py#L114

Anyway, it seems this requirement might be relaxed for the manual mode. It could improve usability to change the text without changing the percentage... For the other modes it does not make much sense.

But even if both params become optional, if you use them in positional form the first will always be the percentage, so it is good to send them named!

You're welcome! :smile: