prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Add pause dialog from inside ProgressBar
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
How can I open a dialog from within another app, e.g. a progress bar?
I would like to achieve something like the below, but currently the parent app continues rendering.
#!/usr/bin/env python
import time
from prompt_toolkit import HTML
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.shortcuts import ProgressBar, yes_no_dialog
def main():
bottom_toolbar = HTML(
' Press <b>[p]</b> to pause'
)
kb = KeyBindings()
paused = [False]
@kb.add("p")
def _(event):
paused[0] = True
with ProgressBar(key_bindings=kb, bottom_toolbar=bottom_toolbar) as pb:
for _ in pb(range(800)):
if paused[0]:
result = yes_no_dialog(
title="Paused.", text="Do you want to continue?"
).run()
if result:
paused[0] = False
else:
break
time.sleep(0.1)
if __name__ == "__main__":
main()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ProgressBar, yes_no_dialog, and KeyBindings entry points shown in the issue, and reproduce the example to observe the rendering behavior. The work is complete when a dialog can be opened from within an active ProgressBar without the parent app continuing to render underneath it, while the pause and resume flow remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100