Bat: Discussion: a builtin pager for 'bat'

Created on 5 Jun 2020  Â·  7Comments  Â·  Source: sharkdp/bat

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)
  • Possibility to always draw the header at the top of the screen, even when scrolling down (#908)
  • Builtin --follow support (#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.

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. less comes 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:
out

I'd be happy to hear about your thoughts and ideas!

help wanted question

Most helpful comment

I'm 100% in support for all the advantages this would provide.

The obvious downsides are:

  • this will be a lot of work :smile:

It would be, but the payoff would be amazing. All those useful features would make bat even better than it currently is.

One way to circumvent the [volume of bug reports] would be to make this an opt-in feature, at least in the beginning.

I did some brainstorming on my own about this a while back, and I came to the same conclusion. Making it an opt-in flag (--pager=pager-lib-name) would be a better user experience compared to suddenly changing the pager they use. It should also help reduce the potential for duplicate issues, since not everybody would be experiencing them at the same time.

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:
out

That looks great! I'd be happy to help contribute to it when you feel that it's ready for more contributors :)

I'd be happy to hear about your thoughts and ideas!

Scroll anchoring. When you resize the terminal, having your scroll position jump up or down because of soft-wrapped lines is a frustrating experience. Passing metadata along with each line that defines an anchor could help the pager automatically adjust the scroll position to the new location of the previous anchor.

All 7 comments

I'm 100% in support for all the advantages this would provide.

The obvious downsides are:

  • this will be a lot of work :smile:

It would be, but the payoff would be amazing. All those useful features would make bat even better than it currently is.

One way to circumvent the [volume of bug reports] would be to make this an opt-in feature, at least in the beginning.

I did some brainstorming on my own about this a while back, and I came to the same conclusion. Making it an opt-in flag (--pager=pager-lib-name) would be a better user experience compared to suddenly changing the pager they use. It should also help reduce the potential for duplicate issues, since not everybody would be experiencing them at the same time.

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:
out

That looks great! I'd be happy to help contribute to it when you feel that it's ready for more contributors :)

I'd be happy to hear about your thoughts and ideas!

Scroll anchoring. When you resize the terminal, having your scroll position jump up or down because of soft-wrapped lines is a frustrating experience. Passing metadata along with each line that defines an anchor could help the pager automatically adjust the scroll position to the new location of the previous anchor.

Wow. I just came across bat the other day and fell in love with the beauty of it. Everything mentioned would make bat a leader in the paging category. Thanks for your passion and hard work

The addition of vim color schemes would be great

I'd also like to see this becoming a printer-friendly solution - not only the on-screen anchor, but per-printed-page anchors (header and footer).

"pager" as a library

A lot of tools could be better with a good library for this. man (and things like git help that invoke man) doesn't support terminal resizing properly either.

Is it an option to simply make the pager a separate program, and have bat recommend using it? That way Unix philosophy is followed more closely.

@metov I'm not very picky and as long as it obeys my export PAGER='/usr/bin/less -iR' so I don't have to manually shove | less -iR after every invocation or wrap it in a shell function, I'd like that. but the proposal does make good points for why to have a built-in one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rien333 picture rien333  Â·  3Comments

yannallain picture yannallain  Â·  3Comments

HakubJozak picture HakubJozak  Â·  3Comments

tbsvttr picture tbsvttr  Â·  3Comments

SamuelMarks picture SamuelMarks  Â·  3Comments