Open GNUGradyn opened 3 years ago
I'm trying to write a console using this library. If I just use print() to print data, everything works as expected
from prompt_toolkit import PromptSession from prompt_toolkit.patch_stdout import patch_stdout from prompt_toolkit import print_formatted_text from prompt_toolkit.formatted_text import FormattedText import asyncio async def printer(): while True: print("DATA TIME") await asyncio.sleep(1) async def prompter(): session = PromptSession() while True: with patch_stdout(): input = await session.prompt_async('$ ') async def main(): printer_task = asyncio.create_task(printer()) await prompter() await printer_task asyncio.run(main())
But if we do the exact same thing, literally just replacing the print() with a print_formatted_text(), everything falls apart
from prompt_toolkit import PromptSession from prompt_toolkit.patch_stdout import patch_stdout from prompt_toolkit import print_formatted_text from prompt_toolkit.formatted_text import FormattedText import asyncio async def printer(): while True: print_formatted_text(FormattedText([('#0000FF', '[I] '),('', "DATA TIME")])) await asyncio.sleep(1) async def prompter(): session = PromptSession() while True: with patch_stdout(): input = await session.prompt_async('$ ') async def main(): printer_task = asyncio.create_task(printer()) await prompter() await printer_task asyncio.run(main())
This is definitely a bug. This is supposed to work. I'll look into it.
https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1455
Thanks for the update. However, this still appears to be an issue with the latest version on pypi
Any update on this?
I'm trying to write a console using this library. If I just use print() to print data, everything works as expected
But if we do the exact same thing, literally just replacing the print() with a print_formatted_text(), everything falls apart