TERM ANSI escape sequences compatibility between xterm and screen although infocmp does not say so

I am making an script in zsh on mac that uses tmux and after the amazing https://unix.stackexchange.com/users/22565/st%c3%a9phane-chazelas answer, I found out that when I use tmux, it uses a different interpreter that that of my host machine.

Therefore, as I am outputing the same literals to both tty and tmux pane from my script tput commands, I wanted to know whether there was some incompatibility on the ANSI escape sequences I am producing.

I found that $TERM is xterm-256color in my mac and screen-256color within a tmux pane, therefore I issued

%> infocmp xterm-256color screen-256color

I am using code that uses tput clear, civis, sgr0, cnorm, rc, sc, home, cd, cr, el, cub1, cud, cuf. The code is working, the ouput is produced in the xterm context with tput and is well rendered on both tty and tmux when tee’ed.

But according to infocmp, clear for instance has difference escape sequences on both terms:

comparing xterm-256color to screen-256color.
        clear: 'E[HE[2J', 'E[HE[J'

so how can it work?

As a side-question, msot of my commands don’t show up in the comparison, does thi mean they are not theoretically supported or that they are common in both terms?

Asked By: Whimusical

||

It works because in a (ECMA-48) standard terminal, there is no difference in the effect of the two strings. Both send the cursor to the upper left corner of the screen. Then one (E[J) clears the remainder of the screen while the other (E[2J) clears the whole screen:

CSI Ps J  Erase in Display (ED), VT100.
            Ps = 0  ⇒  Erase Below (default).
            Ps = 1  ⇒  Erase Above.
            Ps = 2  ⇒  Erase All.
            Ps = 3  ⇒  Erase Saved Lines, xterm.

(from XTerm Control Sequences)

Answered By: Thomas Dickey
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.