prompt-toolkit / prompt-toolkit/python-prompt-toolkit
`print_formatted_text()` messes up terminal output
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
I've been developing a console application that prints logs while simultaneously prompting the user for input, similar to patch-stdout example.
When I switched to print_formatted_text() instead of print() things messed up. I expect the prompt to stay the last line and for all prints to go above it.
I've been able to reproduce the issue with the patch-stdout.py example by changing print()s to print_formatted_text().
When running it with print() (without any modifications):
$ python patch-stdout.py
i=1
i=2
i=3
i=4
Say something:
Say something: moves below the prints.
When replacing print() with print_formatted_text():
$ python patch-stdout.py
i=1
Say something: i=2
i=3
i=4
i=5
i=6
Say something: is on the 2nd line, and i=2 is appended to it.
I expected the code to behave exactly the same.
How can I use print_formatted_text() without it breaking my terminal output?
Thanks!
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 examples/prompts/patch-stdout.py and reproduce the behavior by replacing print() with print_formatted_text(). Compare how each function writes while the prompt is active, then verify that formatted output appears above the prompt and leaves the prompt as the last line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100