more: gate tty-only writes; extract clear_line/highlight_text#12224
Open
aaron-ang wants to merge 1 commit into
Open
more: gate tty-only writes; extract clear_line/highlight_text#12224aaron-ang wants to merge 1 commit into
aaron-ang wants to merge 1 commit into
Conversation
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.
|
GNU testsuite comparison: |
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.
Motivation
Pagerwrote ANSI escape sequences (Attribute::Reverse,Clear(...),MoveTo(...)) unconditionally. When stdout is not a tty — e.g.more file.txt | cator 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()— queuesClear(CurrentLine).highlight_text(text)— wrapstextinReverse…Reset.Applied at every site that wrote raw ANSI:
handle_from_line— "cannot seek to line" error prompthandle_pattern_search— "pattern not found" promptdisplay_multi_file_header— line clear before headerupdate_display— gateprint_over/clean_printcursor moves onis_tty()draw_lines— line clear at top, pattern highlight in bodydraw_status_bar— reverse-video status bardraw_status_barnow returnsio::Result<()>instead of.unwrap()-ing its write.Carved out from #10667 per the request to split.