[Techtalk] prevent screen from clearing

Akkana Peck akkana at shallowsky.com
Tue Sep 27 12:05:00 EST 2005


gabrielle writes:
> Using the (I assume bash) terminal window on my linux desktop (gnome on
> fedora core 3) there is this really annoying "feature" configured - when
> I view a document (with vi, view, man, who knows what else) and then
> exit out of the document, the screen clears.  This bugs the crap out of
> me because a lot of time I'll page through a man page until I find what
> I was looking for, and then quit out of it, expecting the stuff I was
> just looking at to stay on the page (and in the scroll buffer) for
> reference.  I can get around it by piping the output through "more" but
> I'm thinking I shouldn't have to do that, just because I don't have to
> do it in bash on my solaris boxes. ;)
> 
> Where do I look to configure this?

That drives me crazy too! I'm glad I'm not the only one.

How to configure it depends on what terminal you're using.

If you're using xterm or any variant of it, such as rxvt, it's
really easy: you can set an X resource. Put this in your
.Xdefaults or .Xresources:

XTerm*titeInhibit: true

"tite" may seem like a strange term; it comes from the fact that in
the old "termcap" way of specifying terminal capabilities, the
string to save and restore the "alternate screens" were called
ti and te (I'm sure those stood for something, but if I ever knew
what, I've forgotten). If you don't use X resources for anything
else, you can also set this via a command-line option.

Unfortunately, modern terminal emulators such as gnome-terminal have
decided for our own good that users should not be allowed to make
choices, and as far as I was ever able to determine, there's no way
to tell gnome-terminal to turn it off. And vim and man don't seem to
have a way to disable that behavior either.

But wait! Don't lose hope yet. Because programs such as vi and man
use the "terminfo" database (which does the same thing as termcap
used to) to determine what sort of terminal they're talking to and
how to tell that terminal to save and restore the alternate screen.

It turns out that instead of ti/te, the string "rmcup" is the one
which represents this behavior in terminfo (you can get a little
info on it by googling on rmcup).

So you can trick programs by making a terminfo entry that has no rmcup
entry at all, and using that instead of the standard entry. You're
pretending that you're using a terminal which doesn't have that
feature at all.

I've made a terminfo entry  that emulates "xterm-color" but removes
those entries.  Download it, make a directory in your homedir called
terminfo, and put the file there. Call it xterm-noalt.terminfo.
Then set TERM to xterm-noalt (in bash, export TERM=xterm-noalt) and
you should be good to go.

I thought I'd written this up back when I first did it, but I don't
seem to have it online, so I've made an online copy of this posting
with a link to the relevant file. Gabrielle, I hope you don't mind if
I quote part of your posting anonymously (if you do mind, let me know
and I'll remove that part).

http://shallowsky.com/linux/noaltscreen.html

	...Akkana


More information about the Techtalk mailing list