Open the pager at source lines and highlighted positions - #3990
Open
Matei02355 wants to merge 2 commits into
Open
Open the pager at source lines and highlighted positions#3990Matei02355 wants to merge 2 commits into
Matei02355 wants to merge 2 commits into
Conversation
Matei02355
marked this pull request as ready for review
September 7, 2026 17:01
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.
Opening at a source line currently requires calculating the header offset manually, and wrapping or selected ranges make that offset incorrect. Add --scroll-to=LINE, --center-highlight with --highlight-line, and file:line input positions while keeping preceding output available for scrolling back.
Defer pager startup until the target has a rendered line number. Buffer the prefix in memory up to 64 KiB, spill larger prefixes to a temporary file, then drain that prefix and stream the remaining input. Account for headers, wrapping, range snips and squeezed lines. Requests beyond the selected output open at the end without passing a nonexistent line number to less; an absent visible highlight opens at the beginning.
Standard less receives the calculated +Ng and, for centering, -j.5. Custom pager wrappers receive BAT_SCROLL_LINE and BAT_SCROLL_POSITION without injected less options. The built-in pager, BusyBox less, more and most report that positioning is unsupported. These forms require one input and respect existing paging settings; redirected output still contains all selected lines.
Interpret a UTF-8 file:line argument only if the literal path is missing, its suffix is a positive integer, and its prefix names an existing file. Existing paths, broken symlinks and Windows alternate data streams take precedence. Add --literal-file-names to disable the shorthand, and let explicit positioning flags override its position. Preserve language detection and the original file's header name.
Document the behavior in help, README and the manual, add all four shell completions, and expose positioning through Config and PrettyPrinter without changing OutputType or OutputHandle variants.
Validation: 489 all-feature tests passed (7 ignored), including 16 new Linux tests for line mapping, wrappers, streaming before EOF, spilling, early pager exit, filename precedence and unchanged unpaged output. All 8 default-feature help tests passed. Six real less 590 PTY sessions verified initial positions and scrolling back, including empty input and beyond EOF. Clippy with warnings denied, formatting, rendered Bash/Zsh completion syntax, and library builds with paging enabled and disabled passed. An additional Windows CI regression covers numeric NTFS streams.
Fixes #1185. Fixes #2363. Fixes #2576.