3

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
0
1
2
3
4
5
6
7
8
9
~$ 

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:\
        :am:xn:ms:mi:G0:km:\
        :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
        :cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
        :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
        :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
        :li#24:co#80:us=\E[4m:ue=\E[24m:so=\E[3m:se=\E[23m:\
        :mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:sr=\EM:al=\E[L:\
        :AL=\E[%dL:dl=\E[M:DL=\E[%dM:cs=\E[%i%d;%dr:dc=\E[P:\
        :DC=\E[%dP:im=\E[4h:ei=\E[4l:IC=\E[%d@:\
        :ks=\E[?1h\E=:ke=\E[?1l\E>:vb=\Eg:\
        :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
        :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\E[15~:k6=\E[17~:\
        :k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:\
        :kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:@7=\E[4~:kP=\E[5~:\
        :kN=\E[6~:eA=\E(B\E)0:as=^N:ae=^O:\
        :vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
        :Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
        :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:

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,
        acsc=++\,\,--..00II``aaffgghhjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        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,
        tbc=\E[3g,

2 Answers 2

2

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.

1

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.

Versions:
GNOME Terminal 2.26.0
Screen version 4.00.03jw4 (FAU) 2-May-06
XTerm(241)

1
  • 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... Aug 15, 2009 at 16:59

You must log in to answer this question.

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