Skip to content

more: gate tty-only writes; extract clear_line/highlight_text#12224

Merged
sylvestre merged 1 commit into
uutils:mainfrom
aaron-ang:more-tty-gate
May 12, 2026
Merged

more: gate tty-only writes; extract clear_line/highlight_text#12224
sylvestre merged 1 commit into
uutils:mainfrom
aaron-ang:more-tty-gate

Conversation

@aaron-ang

@aaron-ang aaron-ang commented May 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

Pager wrote ANSI escape sequences (Attribute::Reverse, Clear(...), MoveTo(...)) unconditionally. When stdout is not a tty — e.g. more file.txt | cat or any redirect — those bytes leak into the downstream consumer as garbage.

Changes

Two small helpers on Pager, each a no-op when stdout is not a tty:

  • clear_line() — queues Clear(CurrentLine).
  • highlight_text(text) — wraps text in ReverseReset.

Applied at every site that wrote raw ANSI:

  • handle_from_line — "cannot seek to line" error prompt
  • handle_pattern_search — "pattern not found" prompt
  • display_multi_file_header — line clear before header
  • update_display — gate print_over / clean_print cursor moves on is_tty()
  • draw_lines — line clear at top, pattern highlight in body
  • draw_status_bar — reverse-video status bar

draw_status_bar now returns io::Result<()> instead of .unwrap()-ing its write.

Carved out from #10667 per the request to split.

Pager unconditionally wrote ANSI sequences (Attribute::Reverse, Clear,
MoveTo) even when stdout was not a tty, leaking escape codes into pipes.
Gate each on stdout.is_tty() through two helpers and apply them at every
call site: error prompts, multi-file header, screen update, line clear,
pattern highlight, and the status bar.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.

@sylvestre sylvestre merged commit 6f102bf into uutils:main May 12, 2026
171 checks passed
nonontb pushed a commit to nonontb/coreutils that referenced this pull request May 28, 2026
…#12224)

Pager unconditionally wrote ANSI sequences (Attribute::Reverse, Clear,
MoveTo) even when stdout was not a tty, leaking escape codes into pipes.
Gate each on stdout.is_tty() through two helpers and apply them at every
call site: error prompts, multi-file header, screen update, line clear,
pattern highlight, and the status bar.
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