Avoid repeated TTY readline output with TERM=dumb - #923
Open
JoelTowell wants to merge 4 commits into
Open
Conversation
JoelTowell
force-pushed
the
fix-dumb-terminal-readline-rerender
branch
from
September 1, 2026 14:06
04caca4 to
8a1a765
Compare
JoelTowell
marked this pull request as ready for review
September 1, 2026 14:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reline's dumb IO gate can be attached to a TTY, but it cannot repaint one.
When
TERM=dumbis set, Reline selectsReline::Dumb.inner_readlinestill drives the display machinery: it renders the line editor, rerenders after input changes, renders the accepted line, and then moves the cursor back to column 0.That is fine for an IO gate that can move the cursor over the previous frame. It is an issue for
Reline::Dumb, where the cursor movement methods intentionally do nothing.Reline::Dumb#buffered_outputalso just yields, so those render writes go straight to output.With a TTY, submitted input is already echoed by the terminal. Reline then appends intermediate render output after that. Typing
hellocan produce output like:This is related to #660.
Reproduction
The first commit on this branch adds failing coverage for this. It runs
Reline.readlinetwice under a PTY withTERM=dumb, so both input and output are TTYs.It can be checked out independently to see the current behaviour.
Solution
Buffer writes inside
Reline::Dumb#buffered_outputwhen input and output are both TTYs.The first buffered render is still written, so the prompt is visible. Complete lines are also still written, so accepted input remains visible in captured TTY output. Other render frames are dropped, because
Reline::Dumbhas no cursor operation that could apply them in place.When input or output is not a TTY,
buffered_outputkeeps yielding directly and preserves the existing write path.