You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Progress with multiple tasks. At some point, I want to have a user interaction by prompting. To not clutter the output, I made the Progress transient. The idea was to stop() the progress, query the user, and start() the progress again. If I do so, however, several lines are deleted from the output. I created a MWE to demonstrate this bug (ignore the function input_with_prefill for the beginning):
importtimefromrich.consoleimportConsolefromrich.progressimportProgressdefinput_with_prefill(prompt="", prefill=""):
""" This is a function I use to offer the user a prompt with a prefill they can edit. I don't think it has something to do with this bug. """importreadlinedefhook():
readline.insert_text(prefill)
readline.redisplay()
readline.set_pre_input_hook(hook)
# Write the prompt with prefil to the terminal.result=input(f"Line 3: {prompt}").strip()
readline.set_pre_input_hook()
returnresultconsole=Console()
# Print two lines of info. This is important info for the user.console.print("Line 1: Print some important info.")
console.print("Line 2: Print some more important info.")
withProgress(console=console, transient=True) asprogress:
# Do some work and analysize stuff...task_a=progress.add_task("Analyzing your fridge...")
task_b=progress.add_task("Analyzing bottom fridge drawer...")
task_c=progress.add_task("Analyzing left corner of drawer...") # <-- [1] Try out-commenting.time.sleep(0.5)
# We want to ask the user something, so hide the progress bars.progress.stop()
# Ask the user.favorite_food=input_with_prefill(prompt="Favorite Food? ", prefill="Pizza")
#progress.print() # <-- [2] Try remove comment.#progress.print() # <-- [2] Try remove comment.# Now that we have the answer we can show the progress bars again and keep processingprogress.start()
time.sleep(0.5)
# Print the result of the analysis.progress.print(f"Line 4: Favorite food is {favorite_food}.")
Expected Behavior
I thought the output would look like this:
Line 1: Print some important info.
Line 2: Print some more important info.
Line 3: Favorite Food? Hamburger
Line 4: Favorite food is Hamburger.
Actual Behavior
Somehow, two lines are deleted:
Line 1: Print some important info.
Line 4: Favorite food is Hamburger.
Insights
It has to do with the number of tasks. If you out-comment one task (e.g., task_c, see [1]), it will only remove one line instead of two.
If you know the number of tasks, you can compensate by printing n-1 new lines (see [2]), with n = number of tasks.
Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.
Platform
Click to expandPlatform Info
name@host ~ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
name@host ~ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
name@host ~ uname -a
Linux phi-deianeira 5.10.0-25-amd64 #1 SMP Debian 5.10.191-1 (2023-08-16) x86_64 GNU/Linux
name@host ~ python --version
Python 3.9.2
name@host ~ zsh --version
zsh 5.8 (x86_64-debian-linux-gnu)
Describe the bug
I have a Progress with multiple tasks. At some point, I want to have a user interaction by prompting. To not clutter the output, I made the Progress transient. The idea was to
stop()
the progress, query the user, andstart()
the progress again. If I do so, however, several lines are deleted from the output. I created a MWE to demonstrate this bug (ignore the functioninput_with_prefill
for the beginning):Expected Behavior
I thought the output would look like this:
Line 1: Print some important info. Line 2: Print some more important info. Line 3: Favorite Food? Hamburger Line 4: Favorite food is Hamburger.
Actual Behavior
Somehow, two lines are deleted:
Insights
task_c
, see [1]), it will only remove one line instead of two.n-1
new lines (see [2]), withn
= number of tasks.Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.
Platform
Click to expand
Platform InfoOutput of
python -m rich.diagnose
Output of
pip freeze | grep rich
The text was updated successfully, but these errors were encountered: