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.
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 usingprint_formatted_text
.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 apromptsession
, 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.