Skip to content

Open the pager at source lines and highlighted positions - #3990

Open
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:pager-start-line-1185-20260907
Open

Open the pager at source lines and highlighted positions#3990
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:pager-start-line-1185-20260907

Conversation

@Matei02355

Copy link
Copy Markdown
Contributor

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.

@Matei02355
Matei02355 marked this pull request as ready for review September 7, 2026 17:01
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.

Support moving to given line number Option to center view on line passed to --highlight-line Open file starting at line number

1 participant