Discussion: a builtin pager for 'bat'
Author: sharkdpCreated Jun 5, 2020Updated Sep 11, 2026
Labelsfeature-requestpager-related
Let's use this ticket to discuss some ideas and possible upsides/downsides of writing our own custom pager library that we could use instead of calling an external $PAGER process (or, essentially, less).
A few advantages if we would use a builtin pager in bat:
- Have one consistent pager experience across all operating systems. No need to call external programs that might not be available. No special handling / bug fixing for different versions of
less. Consistent "quit if one screen" handling, and much more (#860, #1000, #717, #710, #681, #520, #415, #312, #271, #519, #376, #887, #943, #838, …) - Handling of terminal resize events. This would be my personal main motivation. (#294, #322, #921, #1009)
- Open editor with a key press (#358, #464, #528, #697, #1051, #1607)
- Possibility to always draw the header at the top of the screen, even when scrolling down (#908)
- Builtin
--followsupport (#457, #808) - Special handling for multiple files? (press 'n' to go to the next file)
- Error handling: we could print errors/warnings in the footer of the pager, instead of in the background (#946)
- Better 'tab' handling (#980, #894)
- Handling of ANSI hyperlinks (#961)
- Reload the displayed file with a keypress.
- Disable style components via keypress. For example: switch off the side bar with a keypress - for easy copy&paste.
- Properly handle search with wrapping enabled. Search is currently broken for words being wrapped (#1475)
General advantages of a "pager" as a library (not just for bat):
- Make everything easily configurable: custom header and footer messages, keybindings
- Bidirectional communication: send events like "terminal resize" or key presses back to the main application to trigger a redraw or other actions.
The obvious downsides are:
- this will be a lot of work :smile:
- I'm sure there will be TONS of bug reports regarding obscure terminal emulators and operating systems where things are not working as expected - which results in even more work.
lesscomes with 36 years(!!) of experience.
One way to circumvent the second point would be to make this an opt-in feature, at least in the beginning.
I have actually started to implement a really simple cross-platform pager-as-a-library like this in a private repository. The first results look promising :smile:
I'd be happy to hear about your thoughts and ideas!
Source: sharkdp/bat