Skip to content

Avoid repeated TTY readline output with TERM=dumb - #923

Open
JoelTowell wants to merge 4 commits into
ruby:masterfrom
JoelTowell:fix-dumb-terminal-readline-rerender
Open

Avoid repeated TTY readline output with TERM=dumb#923
JoelTowell wants to merge 4 commits into
ruby:masterfrom
JoelTowell:fix-dumb-terminal-readline-rerender

Conversation

@JoelTowell

@JoelTowell JoelTowell commented Sep 1, 2026

Copy link
Copy Markdown

Problem

Reline's dumb IO gate can be attached to a TTY, but it cannot repaint one.

When TERM=dumb is set, Reline selects Reline::Dumb. inner_readline still 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_output also 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 hello can produce output like:

0> hello
hhehelhellhello0> hello
"hello"

This is related to #660.

Reproduction

The first commit on this branch adds failing coverage for this. It runs Reline.readline twice under a PTY with TERM=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_output when 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::Dumb has no cursor operation that could apply them in place.

When input or output is not a TTY, buffered_output keeps yielding directly and preserves the existing write path.

@JoelTowell
JoelTowell force-pushed the fix-dumb-terminal-readline-rerender branch from 04caca4 to 8a1a765 Compare September 1, 2026 14:06
@JoelTowell
JoelTowell marked this pull request as ready for review September 1, 2026 14:15
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.

1 participant