0

I’m using GNU Screen inside mintty. To get the scroll wheel to work, I had to switch the mintty scroll wheel mode with an escape code (^[[?7787h). This has the effect that the scroll wheel does not work in less anymore. To fix this, I would need less to send the appropriate escape codes to the outer terminal on start and exit.

I found the ^[P escape code that can be used to send escape codes to the terminal running Screen. So I wanted to add ^[P^[[?7787l to the ti termcap inside screen. To achieve this I added this line to my .screenrc:

termcapinfo * "" "\EP\E[?7787l\E[?1049h"

But that did not affect less at all. I know that ^[P^[[?7787l works – if I just echo it, everything is fine. I could just write a less wrapper that handles that, but I would prefer to be able to do this via termcap, as it would then work in all aplications, not just in less.

So my question is: How can I change which escape codes less sends to the terminal when it switches to the alternative screen?

1 Answer 1

1
+50

This command should work:

termcapinfo * "" "ti=\EP\E[?7787l\E\\\E[?1049h:te=\EP\E[?7787h\E\\\E[?1049l"

(Replacing * with a more specific name for your terminal type would be even better, but I don't know what TERM value is set by mintty.)

Important differences from your version:

  1. The second and third parameters of the termcapinfo command must contain termcap defines (name=value) separated by :, not just a bare escape sequence.

  2. The ^[P escape sequence must be terminated by ^[\, otherwise too much further output goes to the terminal directly without proper processing by Screen (there is some safeguard to avoid locking up Screen completely if the termination sequence is forgotten, but the display will still be messed up).

  3. You should change both ti and te, so that exiting from less (or any other fullscreen program) restores the previous state properly.

Of course, if you invoke less with the -X option, the mouse wheel will not work properly, because with this option less does not send the ti and te strings to the terminal. Remember that this option might be specified not directly in the less command line, but also through the LESS environment variable.


However, if less is compiled to use terminfo instead of termcap, the third parameter of the termcapinfo command will not change the behavior of less, because it influences only the contents of the TERMCAP environment variable exported by screen to its subprocesses, and the terminfo database contents cannot be changed dynamically. In this case you will need to use utilities like infocmp and tic to create a terminfo source entry which contains smcup and rmcup values with your modifications, and then compile the entry to the binary format; then use term <your-entry-name> in .screenrc to use this entry.

1
  • Thx a lot. I had (1) and (3) right, just messed that up in my question. (2) was my problem. It also turns out that the cygwin less is compiled with terminfo, so I also had to complie a new terminfo. Screen helps with that: aperiodic.net/screen/commands:dumptermcap
    – Chronial
    May 7, 2013 at 13:14

You must log in to answer this question.

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