Skip to content

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

Open
aaron-ang wants to merge 1 commit into
uutils:mainfrom
aaron-ang:more-tty-gate
Open

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

Conversation

@aaron-ang
Copy link
Copy Markdown
Contributor

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

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.

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