Avoid terminal rendering for non-TTY readline output - #922
Open
JoelTowell wants to merge 3 commits into
Open
Conversation
JoelTowell
force-pushed
the
fix-non-tty-readline-output
branch
from
August 25, 2026 15:17
3a2c856 to
09436af
Compare
JoelTowell
marked this pull request as draft
August 25, 2026 15:25
JoelTowell
force-pushed
the
fix-non-tty-readline-output
branch
from
August 25, 2026 15:42
09436af to
5513a1a
Compare
JoelTowell
marked this pull request as ready for review
August 25, 2026 16:07
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 decides which IO gate to use before
readlineknows whether it is actually writing to a terminal. On non-Windows platforms,Reline::IO.decide_io_gatecan selectReline::ANSIwheneverTERMis notdumb.That selection is currently treated as enough for
inner_readlineto run the interactive display path. It updates dialogs, renders the line editor, renders the accepted line, and finally moves the cursor back to column 0. That is fine when stdout is a terminal, because those operations update what the user sees in place. It is an issue when stdout is a pipe, because the display output is captured as ordinary output.With the ANSI IO gate, the final cursor movement writes an escape sequence, so captured output can contain bytes such as
\e[1G. That is the escape-sequence symptom in #886.TERM=dumbdoesn't help. It switches toReline::Dumb, where cursor methods intentionally do nothing. Butinner_readlineis still trying to render the line editor. Since the cursor methods do not move back over the previous display, the prompt and input text are left in place and appended again. That is the repeated-output symptom in #886, and relatedTERM=dumbbehaviour is discussed in #660.Reproduction
The first commit on this branch adds failing coverage for the non-TTY cases this PR changes. It can be checked out independently to see the behaviour currently on
master.Solution
Reline::Corealready stores the configured output, butinput=only forwards the input to the IO gate. This change stores the configured input as well.readlinenow uses the interactive display path only when both input and output are TTYs. When that check passes, the existing terminal behaviour is unchanged. When it fails,readlinewrites plain output instead: the prompt once, then the accepted line once. EOF still returnsnil, so there is no accepted line to echo.This PR only changes the non-TTY path. It does not try to fix rendering in real TTY sessions, including
TERM=dumbTTY sessions. Those still use the existing terminal path.