Revisiting 256-color terminal support in Fedora

Posted on . Updated on .

I finally went ahead and upgraded my main box to Fedora 24. I only had one issue, related to 256-color terminal support.

In Fedora 24 GNU Screen is able to detect it’s running under a terminal with 256-color support and it’s been compiled itself with that support. It uses that information to choose an appropriate terminfo entry and value for the TERM environment variable. Instead of setting TERM to “screen” and letting “/etc/profile.d/256term.sh” kick in, Screen sets TERM to “screen.xterm-256color” when running under xterm, for example.

This has several advantages. For example, you don’t need to launch a login shell within xterm so 256term.sh is used. Any regular interactive shell will work and have 256-colors support. When launching Vim inside Screen, you don’t need to pass the -T option to preserve the TERM value as I explained in a previous post. Any new Screen window will also have the right TERM value.

Regression: if you do use -T, somewhat confusingly, Screen will refuse to use the given value it’s chosen itself, complaining it’s too long.

$ echo $TERM
screen.xterm-256color
$ screen -T "$TERM"
-T: terminal name too long. (max. 20 char)

Finally, if you use SSH to connect to remote machines from a terminal with that TERM value, remote programs may be confused about the type of terminal. This happened to me and the best way to solve it, in my opinion, is to use a wrapper script for “ssh” that sets a more “classic” value for TERM before launching the real “ssh”. This is what I use as “$HOME/bin/ssh”:

#!/bin/sh
case "$TERM" in
   *screen*) export TERM=screen ;;
   *xterm*)  export TERM=xterm  ;;
   *) ;;
esac
exec /usr/bin/ssh "$@"
Load comments