0

When viewing a long file in Terminal with less (or man, which uses less internally), I can use two-finger gesture to scroll up and down the file; it's great. But less on OS X has an annoying problem: When I quit, it resets the screen back to what it looked like before I started less.

% date
Sun 30 Oct 2016 16:18:23 CET
% man less
% (hmm... where did my output go?)

When I quit I want to see the next prompt appear below the last screenful I was viewing in less. I can achieve this by using less -X or setting LESS=-X, which suppresses the terminal initialization sequences. Unfortunately, -X also turns off the mouse-scrolling feature. Is there a way to suppress the screen clearing but still be able to scroll with the trackpad?

As I understand it, this would require using a different set of terminfo settings. I cannot make heads or tails of the whole terminfo infrastructure. Does anyone have a solution? I'm on El Capitan, in case it makes any difference.

  • See this, which may or may not help. – tubedogg Oct 30 '16 at 20:05
  • That's exactly the same question, thanks! It helps, though unfortunately by explaining that a solution is impossible at the moment. The proposed hack is not a bad idea, though! (Many years ago I made some enhancements to less, so who knows...) – alexis Oct 30 '16 at 21:56
  • If you want to write an answer that just refers to the superuser.so answer, I'll accept it. – alexis Oct 30 '16 at 21:56
1

This question is nearly identical to a question asked on SuperUser. Here's a portion of the answer:

So there you are: Either you switch to alternate screen and the terminal's hack converts scroll events into keypresses for less, and the normal screen is restored when you quit; or you don't, and then there can't be any magic converting scroll events to keypresses and less doesn't understand the scroll events.

So what could be done? Well, either implement mouse support in less and let it handle scroll events itself (and live with a nondefault click or copy-paste behavior), or implement another weird hack: upon quitting, after reverting to the normal screen, less could for the last time print a screenful of content, repeating whatever was displayed before you quit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .