Skip to content

gh-75512: Keep the prompt with the input in progress when a thread prints in the IDLE Shell - #157706

Merged
terryjreedy merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-75512-async-output
Sep 20, 2026
Merged

terryjreedy merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-75512-async-output

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The Shell sidebar shows the prompt on the line after a newline tagged console. Output which arrives while a prompt is shown (for example from a thread) was inserted after that newline, so the output got the prompt and the statement being entered lost it. Now the tag is moved from that newline to the last newline of the output, so the prompt stays with the input in progress. Unterminated output shares the line with the input until its newline arrives, as in a terminal.

🤖 Generated with Claude Code

…ead prints in the IDLE Shell

Output written while a prompt is shown was inserted after the newline
which marks the prompt, so the statement being entered lost it.  Now
the prompt mark is moved after the output.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 17, 2026
@terryjreedy

Copy link
Copy Markdown
Member

Fail. Late output causes the prompt to disappear until I finish line and hit Enter.

go
do_work
int(  # prompt only appears when hit Enter.

Copied with prompts (spaces ignored). After )\n,

go
do_work
>>> int()
0
>>> 

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Thanks, reproduced. The sidebar is redrawn while the output is inserted, before the prompt tag is re-added, so the prompt only came back on the next line-count change. Fixed by updating the sidebar after moving the tag (as showprompt() does), and the test now checks the sidebar. Output without a final newline still ends up on the input line; handling that needed a provisional newline, which I dropped as too complicated.

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definite improvement. People should send async output as complete lines.
To test this further I should merge and use it.

@terryjreedy
terryjreedy merged commit 89c67a9 into python:main Sep 20, 2026
56 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

bedevere-app Bot commented Sep 20, 2026

Copy link
Copy Markdown

GH-157835 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 20, 2026
@bedevere-app

bedevere-app Bot commented Sep 20, 2026

Copy link
Copy Markdown

GH-157836 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 20, 2026
@bedevere-app

bedevere-app Bot commented Sep 20, 2026

Copy link
Copy Markdown

GH-157837 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 20, 2026
terryjreedy pushed a commit that referenced this pull request Sep 20, 2026
…read prints in the IDLE Shell (GH-157706) (#157837)

gh-75512: Keep the prompt with the input in progress when a thread prints in the IDLE Shell (GH-157706)

Output written while a prompt is shown was inserted after the newline
which marks the prompt, so the statement being entered lost the prompt.
If the output ends with a newline, the prompt is moved to the next line.
(cherry picked from commit 89c67a9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
terryjreedy pushed a commit that referenced this pull request Sep 20, 2026
…read prints in the IDLE Shell (GH-157706) (#157836)

gh-75512: Keep the prompt with the input in progress when a thread prints in the IDLE Shell (GH-157706)

Output written while a prompt is shown was inserted after the newline
which marks the prompt, so the statement being entered lost the prompt.
If the output ends with a newline, the prompt is moved to the next line.
(cherry picked from commit 89c67a9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants