prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Is there a way to disable input on a PromptSession?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
Maybe this is a contrived use case:
I create an asyncio task that constantly reads user input using a PromptSession. Meanwhile, another asyncio task renders output using print_formatted_text.
promptsession = PromptSession(...)
async def user_input():
while True:
with patch_stdout():
user_input = await promptsession.prompt_async(...)
# ... use user_input, output will be produced later and enqueued
async def output_proc(queue):
while True:
out = await queue.get()
if out.disable_user_input:
# Disable user input! (but how?)
# promptsession.disable()
...
print_formatted_text(as_html(out))
It would be nice if one could disable/enable the input even though promptsession.prompt_async() is already awaiting.
Although it's perhaps possible to exit() (I'm not sure) and recreate a promptsession, I'd like to preserve the in-memory history (without having to commit it to filesystem). Orchestrating "manually" is an option I would pursue if no "out-of-box" option exists within prompt_toolkit.
Side note, I found that is possible to hide the cursor, as mentioned in this bug.
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 PromptSession.prompt_async and the surrounding patch_stdout and print_formatted_text flow described in the issue. Determine how an already-awaiting prompt can be disabled and enabled without recreating the session or losing in-memory history; done means the pending input is controllable while queued output still renders.
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