Depending on how I run screen
, it either does or does not have the right TERMCAP info.
The symptom of this is that colors don't always show up in my terminal correctly (eg: ls, vim syntax highlighting, etc).
This works fine:
$ echo $TERMCAP
<empty output>
$ screen -S foo
$ screen -r foo
<now I'm inside a screen session>
$ echo $TERMCAP
<long output>
$ ls
<nice pretty colors>
This has problems:
$ echo $TERMCAP
<empty output>
$ screen -d -m -S foo
$ screen -r foo
<now I'm inside a screen session>
$ echo $TERMCAP
<long output, but different than before>
$ ls
<no colors ):>
Now, I can work around this. I can fiddle with my TERMCAP manually, etc.
But I'd really like to understand what's going on.
I'd like to find a 'clean' solution, if possible.
Does anybody know what's going on here?
What difference should it make if I use -d -m
when running screen
?
This is on FreeBSD, if that matters.
Best Answer
When you use the
-d -m
options,screen
starts in detached mode, and in that case does not attempt to improve its terminal description based on your currentTERM
variable. It only looks for yourTERM
variable when it is started normally (not detached). When you attach to the session which was started detached, it is too late to do this initialization based onTERM
.The section 16.1 Choosing the termcap entry for a window in the manual describes some of the fixes it does.
What you saw for the non-working case looks like this:
while the good one looks like this:
In the good case,
screen
noticed thatTERM
was set toxterm
, and added capabilities from that description.You will notice this problem with FreeBSD because the termcap distributed with
screen
does not have color, when you limit the description to the 1023-byte limit assumed by termcap applications (the extra settings are discarded). On other platforms, you likely would be using the description provided by ncurses, which does tell how to use color. The difference is not due to the library used; althoughscreen
is a termcap application, it uses ncurses on FreeBSD:Instead, the difference is due to
TERM=xterm
and a real xterm less apparent (except to people using xterm, of course).Somewhat ironically, one may notice that
screen
setsTERMCAP
to a multi-line format. That was used in 4.2BSD and 4.3BSD, but made obsolete in 4.4BSD (around 25 years ago), with the switch to using hashed databases and at the same time discarding the whitespace (which counted against the 1023 byte limit on termcap size). Since FreeBSD switched to using ncurses in the 1990s, that format is more out of date, with few applications relying on theTERMCAP
variable. Butls
is one of those.screen
does have an option-T
which should help with this by specifying a particular termcap entry (which has color), but on testing it, appears that cannot solve the problem.Further reading: