Closed Snurppa closed 1 year ago
Thanks for the clear feature request!
Looking at how less
does this (⭐ for the link to the less
source code), in the main loop prompt()
function (which I guess prints the prompt at the bottom of the page), they check:
entire_file_displayed()
returns true
quit_if_one_screen
is true
If all of those are fulfilled, then they drop out.
We can do this.
When testing a bit I noted that unless -F
is combined with -X
, less
just quits without showing anything, which is super confusing. moar
must handle this better.
Outstanding considerations:
I'm not getting what you're getting with bat
and less
, possibly because of version inconsistencies?
I have:
less 487 (POSIX regular expressions)
bat 0.22.1
If I tell bat
to use less -F
I don't get any output at all.
With less -FRX
(bail early, don't clear screen and handle ANSI codes) I get a decorated printout.
Either way, I'll just try to mimic what you're getting.
Thanks for looking into it!
possibly because of version inconsistencies?
Yeah, my version is: less 581.2 (POSIX regular expressions)
.
FYI, bat has some default special handling for less
.
To ensure those don't get into our way I used --paging
and --pager
explicitly.
There seems to be some conditional for less
"smaller than 530", maybe that --no-init
is related to what you are seeing with your less
? Don't know the history related to that unfortunately, but maybe that helps you to find more reasoning for the behavior you are seeing, idk.
Thanks, much obliged! :)
edit: Forgot to comment to considerations:
Should we auto disable line numbers in this case?
I don't know, maybe the -F
should do just one thing, quit if those preconditions are met?
And there should/could be other switch to control the line numbers. Looking at bat
, it seems to by default retain the line numbers. My above screenshots actually have taken my custom style config for bat: --style="changes,header-filename,snip"
. So I have configured them to be disabled. And I guess you have bat
also using the default styles, as your output contains the line number.
Should we wait for background syntax highlighting to finish before dropping out
Not sure, maybe here bat
and moar
kind of overlap as both can do some styling. And by default bat
sends that formatted data to less. First idea is that maybe by default moar could apply the highlighting, but also would be good to have some switch to turn it off, if user is only interested in other pager capabilities that moar has to offer, such as the search etc.
All in all, maybe have one option, the -F
, do only one thing in this case, and achieve the other features with other options? At least thinking only in this -F
context that IMO feels most clearest:
Any progress on this? I'm trying to switch to moar
, but this is a deal breaker for me. Thanks.
In progress (slowlyish): https://github.com/walles/moar/commits/johan/quit-if-one-screen
I think this was kind of asked in #75.
There exists
-F
command inless
:Hint to source.
There seems not to be similar option in
moar
.I noticed this as I've used bat for long time, and recently changed to use
moar
as default PAGER.bat
by default usesless
.What changed in behaviour after
less -> moar
is that small files that would fit into one screen were processed withless -F
in bat. Withmoar
they will pop into "full screen mode" (as intended by pager).Demonstration
Created a file with
echo "[Google](https://google.com)" > google.md
With
bat --paging=always --pager='less -F' google.md
less will quit instantly as contents fit to screen:With
bat --paging=always --pager='moar' google.md
moar does not quit (by design naturally):I came here looking for an equivalent
-F
switch so I could adjust howbat
callsmoar
, but seems it does not exist yet.I don't really have background in Go neither in terminal development, so don't (yet) have suggestion how to implement this. Quick first idea from looking to source made me think if the
pager.ReprintAfterExit()
could somehow be used to achieve this? Just missing the "does this fit to screen"/"is eof" logic?I might be able to scratch something during Q1/23, but no time to dig further at this time.
Opened to issue get comments and possible ideas for implementation.
Thanks and happy new year!