Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Programs like less and full-screen editors work well with terminals like xterm and rxvt, because the terminal initialization and uninitialization lets the terminal save current screen contents and restore it after the program exits.

I'm wondering if screen can be configured to act in the same way.

Concrete example:

Let's say I create a simple file foo containing some lines:

for ((i=0;i<10;++i)); do echo $i; done > foo

Now, I use less to view its contents, and immediately quit out of less with q. In screen, the console now looks like this:

~$ for ((i=0;i<10;++i)); do echo $i; done > foo
~$ less foo

If I do the same thing outside a screen environment, and in a plain rxvt terminal window instead, I get this:

~$ for ((i=0;i<10;++i)); do echo $i; done > foo
~$ less foo

The terminal has saved the screen contents and restored them.

Is there anything I can configure in screen to do this, or any entries I should add to termcap or terminfo to support this?

Here's the relevant section in termcap (my TERM=screen):

SC|screen|VT 100/ANSI X3.64 virtual terminal:\

And from terminfo, according to infocmp:

screen|VT 100/ANSI X3.64 virtual terminal,
        am, km, mir, msgr, xenl,
        colors#8, cols#80, it#8, lines#24, pairs#64,
        bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
        clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM,
        cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM,
        dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E(B\E)0,
        flash=\Eg, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@,
        il=\E[%p1%dL, il1=\E[L, ind=^J, is2=\E)0, kbs=\177,
        kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
        kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~,
        kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR, kf4=\EOS,
        kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
        khome=\E[1~, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, nel=\EE,
        op=\E[39;49m, rc=\E8, rev=\E[7m, ri=\EM, rmacs=^O,
        rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[23m,
        rmul=\E[24m, rs2=\Ec, sc=\E7, setab=\E[4%p1%dm,
        setaf=\E[3%p1%dm, sgr0=\E[m, smacs=^N, smcup=\E[?1049h,
        smir=\E[4h, smkx=\E[?1h\E=, smso=\E[3m, smul=\E[4m,
share|improve this question
up vote 2 down vote accepted

I asked the same question on Hacker News, and received this answer:

try "altscreen on".

Putting this line into my ~/.screenrc worked well to fix this issue.

share|improve this answer

I just tried your example, and get the same behaviour within a screen session as in the terminal (i.e. the contents of foo aren't displayed), using Gnome Terminal or xterm.

GNOME Terminal 2.26.0
Screen version 4.00.03jw4 (FAU) 2-May-06

share|improve this answer
I'm running rxvt from Cygwin on Windows and screen on Nexenta (Solaris with GNU userland). I'll see what's the story with term* entries... – Barry Kelly Aug 15 '09 at 16:59

You must log in to answer this question.

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