terminal – Clear to End of Line Uses Wrong Background Color in Screen

colorsgnu-screenterminal

In ZSH prompt expansion, the command %E is supposed to "Clear to end of line."

This works. We see it in the grey bar going all the way across.

enter image description here

However, if I call "screen", the %E stops working:
enter image description here

Any idea what the cause of this is, and how it can be fixed?

Best Answer

When you send one of the ECMA-48 erase control sequences, whether the erasure uses the current background colour or the default background colour varies amongst different terminal types. (In the terminfo database, there is a capability that allows programs to determine what the terminal that they are talking to will do. It is named bce. The termcap equivalent name is ut.) You are setting the current background colour, and then erasing to the end of the line, expecting the erasure to always use that current colour.

screen is a terminal emulator itself. But unlike most hardware terminals its behaviour in this regard is switchable. By default, background colour erase is switched off, and the control sequence causes erasure with the default colour. One switches it on with the bce command. One sets the default for the bce setting in all new screens with the defbce command.

(I say most, because late model DEC VTs provide DEC Private Mode 117 for switching the behaviour. The default for these terminals was the "new" PC-compatible behaviour of erasing with the current colour, and switching Private Mode 117 off would revert back to the "old" VT-compatible behaviour of erasing with the default colour. DEC VT 52x terminals were switchable like screen, except that the host could do the switching and the default was the "new" behaviour, the opposite of screen's default. These terminals were actually newer than screen, by several years.)

So switch it on. It's as simple as that.

Further reading