prompt-toolkit / prompt-toolkit/python-prompt-toolkit

`print_formatted_text()` messes up terminal output

Open
#783 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.