1

Some terminal applications (e.g. mosh) use the terminal in the alternate screen, thereby disabling the terminal emulator's local scrolling. mosh does not allow overriding its terminal settings (as far as I could find), so one simple way to force it to not use the alternate screen and (thus) keep local scrolling working is to tell it the terminal doesn't have an alternate screen:

env TERM=dumb mosh <destination>

mosh now no longer breaks scrolling, unfortunately TERM=dumb also doesn't have any other modern-ish terminal features, such as setting the application name in the titlebar. More useful is TERM=linux, but that still doesn't set the app name in the titlebar.

So, what is the most xterm-like $TERM setting that does not support an alternate screen?

notes:
‑ My default TERM value is xterm-256color.
‑ I realise there are other workarounds, like using tmux inside mosh, but sometimes I don't want to do that.
‑ I realize this only gives me the local scroll buffer, so this still misses output if the mosh session was disconnected and then reconnected itself. But sometimes that is good enough.

JanKanis
  • 1,069

1 Answers1

2

The alternate screen is switched to/from using the smcup and rmcup features of a terminal's terminfo entry (or ti and te in a termcap entry).

You could make a copy of, say, the tmux-256color or xterm-256color entry, edit it to have a different name and empty values for smcup and rmcup, then add your changed version back to the terminfo database by compiling it with tic.

You will need to modify at least the title/desc on the 2nd line (immediately after the # comment), and the smcup & rmcup values

e.g.

mkdir ~/.terminfo
infocmp tmux-256color > /tmp/tmux256-noalt
vi /tmp/tmux256-noalt
tic /tmp/tmux256-noalt

then export TERM=tmux256-noalt (assuming that's what you called it in the /tmp/tmux256-noalt file).

If you want to add the entry to the system's terminfo db instead of ~/.terminfo/, run tic as root (e.g. with sudo).

I very strongly advise reading up on ncurses, terminfo, infocmp, tic, and related topics before starting.

BTW, the current author & maintainer of ncurses, Thomas Dickey, frequents this site and often answers questions about it. You can learn a lot just by reading some of his answers. It's quite likely he has already answered a duplicate of this question, but I didn't find one (didn't search very hard, though).

cas
  • 78,579