git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: why does git set X in LESS env var?

From
DSDragan Simic <dsimic@manjaro.org>
Date
Nov 2, 2023, 14:19 UTC
Message-ID
<79cf1bf35ba6c9348735685b01e0f2f9@manjaro.org>
In-Reply-To
<d54eedf0-7825-44f5-908c-a51541345872@gmail.com>
On 2023-11-02 14:19, Thomas Guyot wrote:
Show 15 quoted lines
> On 2023-11-02 02:48, Dragan Simic wrote:
>> On 2023-11-02 06:48, Thomas Guyot wrote:
>>>         -c or --clear-screen ( and backward compat. -C or
>>> --CLEAR-SCREEN )
>>>                Causes full screen repaints to be painted from the top
>>> line down.  By default, full screen repaints are done by scrolling
>>> from the  bottom  of the screen.
>> 
>> AFAIK, the "-c" option is about the way screen contents is updated 
>> when
>> scrolled, and it exists to aid in resolving possible issues with some
>> terminal emulators.  To make sure, I just tested it, and "-c" doesn't
>> replace "-X".
> 
> That's correct, you need both and also -y0
Hmm, I tried the following:
     GIT_PAGER='less -R -F -X -c -y0'

In my environment (Xfce), the result after scrolling the output of "git log -p" up and down a bit was about 20 copies of the same screen "page" in the scrollback, plus a couple of blank "pages". Not good, unfortunately, and actually much worse than having just "-R -F -X".

Show 19 quoted lines
>> Huh, this confuses me a bit, quite frankly.  Isn't the "-F" option 
>> used
>> specifically to make pagination invisible in case fewer lines than one
>> full screen are displayed?
> 
> Indeed, but when less update from the bottom, it can add new lines and
> let the overflow lines scroll up into the scrollback buffer.
> 
> Then updating it from the top, it draws the whole page, top to bottom.
> That's fine for a full page but not desired for a partial one. Also
> note that on my terminal (rxvt-unicode) when less clears the screen to
> draw the first page the current screen is rolled up into scrollback -
> iirc that's a configurable option, it would be worth testing other
> terminal's behavior on that. IIRC it may also erase it when using the
> wrong termcap file.
> 
> I haven't looked at the code, but I think it could be possibly to
> start the -c behavior only after a full page is drawn, after exiting
> on partial pages, which would give us the best of both worlds.

Does the GIT_PAGER setup, as I described it above, work for you without the described artifacts, in any of the environments you have access to?

Show 14 quoted lines
>>> OTOH by repainting from the top, the scrollback buffer is never
>>> affected. only the last displayed page remains on the terminal.
>> 
>> Just to clarify, it's the "-X" option that creates all the issues, and
>> the "--redraw-on-quit" option is already there to replace it with no
>> associated issues, but the trouble is that only newer versions of
>> less(1) support the "--redraw-on-quit" option.  IOW, it's all about
>> improving less(1) to avoid complex workarounds required to handle
>> different versions, such as the workarounds used in bat(1).
> 
> TBH I haven't tested --redraw-on-quit, even on Debian Bookworm which
> was just released a couple months ago this option isn't available. I
> suspect that the issue isn't -X, but the scrolling behavior controlled
> by -y and the full redraw controlled by -c.

When you get into the terminfo entry definitions, the root cause is that the terminal initialization sequences contain switching to alternate screen, which causes screen contents to be lost when less(1) exits. Thus, "-X" has been actually abused in the pager setups to skip the terminal initialization sequences, which may also result in other issues.

One of the solutions is to edit the terminfo entry manually and remove the escape codes that cause the switching to and from alternate screen, which I tested, but that also introduced another issue -- the screen contents was always present after less(1) exited, which isn't always the desired behavior.

Show 8 quoted lines
> Actually I just tested my
> solution on xfce4-terminal and it doesn't work, the terminal still
> push up stuff above on redraw (noteworthy is with rxvt-unicode the
> first draw pushes the current screen contents up but no other redraw
> does, which is what makes it work so well - I haven't tried to find
> out what is being done exactly... OTOH the redraw on scroll down is
> slightly noticeable there, while impossible to see on xfce4-terminal.
> I'll install the latest less and see what happens with --redraw on

Please test the "--redraw-on-quit" option, so far it's the best available solution, IMHO.

Show 19 quoted lines
>>> If less could only enable this behavior after the first full page
>>> draw, that would be perfect!
>> 
>> Could you, please, elaborate a bit on that?
> 
> I mentioned it slightly above, to be clear it would mean that:
> 
> 1. less starts by just writing lined down as usual, making any lines
> above scroll up and overflow into the scrollback buffer as usual
> 2.  If less draws less than a page, exits as before - the effective
> result is as if pager was cat
> 3. If less reaches a full page and still has lines to write, it turns
> on -c's behavior and further updates happen from the top of the
> screen, preventing scroll up (at least on rxvt-unicode)
> 
> Now, if all other terms misbehave here, that's an issue, making this
> suggestion mostly useless. And considering the number of Windows users
> we absolutely need to test Windows Terminal, and should probably test
> MacOS's term too (whatever that is).

Quite frankly, I think that such a solution would be like "fixing the fix, which is actually an abuse", as I described it above, eventually introducing even more issues, instead of solving the original issue.

Show 20 quoted lines
>>> Dragan, that may be useful if you're discussing with less
>>> developers...
>> 
>> We've basically reached some kind of an agreement about the need for a
>> good solution, which turned out to be rather complex as a result of
>> being quite universal and extensible, which was required for it to,
>> hopefully, be accepted into less(1).  Also, the author of less(1) 
>> seems
>> to be quite busy with some other things, and he prefers to implement 
>> new
>> features himself.
>> 
>> We've also agreed on another new feature for less(1), hopefully, which
>> isn't exactly related, but should be quite useful.  It's about the
>> secure mode for less(1).
> 
> Feel free to cc me on your next correspondence. If there are mailing
> lists archives for the thread I'll fetch them as needed. We have at
> least one working term/switch combination, which IMO is a better start
> than nothing :)

Please test the "--redraw-on-quit" option, AFAICT that's all we need (plus the already mentioned other improvements to less(1), to avoid the version-dependent workarounds), and the distributions will eventually catch up with the newer versions of less(1). If the whole thing has worked for decades as-is, it can continue working that way for a year or two until the packages get updated.

There's actually no two-way mailing list for less(1), the entire project is pretty much a one-man show, so to speak. There's a GitHub page that allows issues to be submitted, but I didn't use that, so I exchanged a few private email messages instead with the author. I've already summed up the important parts of those messages.

Previous: Thomas GuyotNext: Thomas Guyot
Message 33 of 39 in “why does git set X in LESS env var?”
  1. Christoph Anton MittererOct 11, 2023
  2. Junio C HamanoOct 11, 2023
  3. Christoph Anton MittererOct 11, 2023
  4. Dragan SimicOct 11, 2023
  5. Christoph Anton MittererOct 11, 2023
  6. Dragan SimicOct 11, 2023
  7. Christoph Anton MittererOct 11, 2023
  8. Dragan SimicOct 12, 2023
  9. Christoph Anton MittererOct 12, 2023
  10. Dragan SimicOct 12, 2023
  11. Christoph Anton MittererOct 12, 2023
  12. Dragan SimicOct 12, 2023
  13. Christoph Anton MittererOct 12, 2023
  14. Dragan SimicOct 12, 2023
  15. Christoph Anton MittererOct 12, 2023
  16. Dragan SimicOct 12, 2023
  17. Christoph Anton MittererOct 12, 2023
  18. Dragan SimicOct 13, 2023
  19. Christoph Anton MittererOct 13, 2023
  20. Dragan SimicOct 13, 2023
  21. Jeff KingOct 12, 2023
  22. Dragan SimicOct 12, 2023
  23. Junio C HamanoOct 12, 2023
  24. Dragan SimicOct 12, 2023
  25. Junio C HamanoOct 12, 2023
  26. Dragan SimicOct 13, 2023
  27. Christoph Anton MittererOct 12, 2023
  28. Dragan SimicOct 12, 2023
  29. Thomas GuyotNov 2, 2023
  30. Dragan SimicNov 2, 2023
  31. Dragan SimicNov 2, 2023
  32. Thomas GuyotNov 2, 2023
  33. Dragan SimicNov 2, 2023
  34. Thomas GuyotNov 3, 2023
  35. Andy KoppeNov 3, 2023
  36. Dragan SimicNov 3, 2023
  37. Dragan SimicNov 3, 2023
  38. Dragan SimicNov 6, 2023
  39. Dragan SimicMar 21, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.