HowTo: (escape from) rxvt, unicode, 256color, termcap, terminfo and screen (hell)

Hi there.

After struggling quite some time with the terminal settings to produce
a nice looking 256 color with rxvt and screen even over ssh i thought
that my findings might be useful for other users too.

First step is to ensure that all of your programs are properly
compiled. There are now options for the according ports so double
check with [CMD="make"]config[/CMD]!

Having rxvt-unicode and screen compiled with 256 color support you
should not have a problem using this e.g. with vim in X11.

Trouble started for me after trying to use vim over ssh from a linux
box with rxvt-unicode from there.

The environment variable TERM is set to
rxvt-256color which cannot be
found in /etc/termcap. That's pitfall #1.

To solve this create a file in your $HOME called
.termcap. To do this you could run this (be careful,
this will overwrite any existing file if present):
Code:
cat > $HOME/.termcap << EOF
rxvt-256color|rxvt-256color terminal (X Window System):\
  :tc=rxvt-unicode:\
  :tc=rxvt:
EOF

Now vim or whatever program (e.g. ls -G) should reward you with
colored output. After starting up screen you will see that the colors
have vanished again. This is pitfall #2.

It is likely that screen complained already while executing it so
let's fix that first. It will tell you that it cannot find a termcap
entry for rxvt-256color also you just added it to
.termcap.

To make screen recognize your new private termcap entry, you need to
put the content of .termcap into the
TERMCAP environment variable. To do so add something
like this to your shell's rc file (e.g. .bashrc):
Code:
if [ -f ${HOME}/.termcap ]; then
  TERMCAP=$(< ${HOME}/.termcap)
  export TERMCAP
fi

Now log out and log in again but you will see that screen still isn't
happy. That's pitfall #3 (and finally the last one). In your
.screenrc look out for a termcapinfo entry
similar to this:
Code:
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
Modify or create one if needed so that it looks like this:
Code:
termcapinfo xterm-color|xterm-16color|xterm-88color|xterm-256color|rxvt* 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
Restart screen and now you should finally be able to enjoy all of the
256 colors.

I hope this was helpful, any comments or remarks will be appreciated.
 
Still has what I would call the main problem; no 256color in some applications.

First, ~/.termcap should be corrected as follows:

Code:
rxvt-256color|rxvt-256color terminal (X Window System):\
  :Co#256:\
  :tc=rxvt-unicode:\
  :tc=rxvt:

Then for completeness' sake, instruct the urxvt client to always use rxvt-256color as TERM by editing ~/.Xdefaults:

Code:
urxvt*termName: rxvt-256color

But what this is really doing is circumventing a problem that needs to be addressed in /etc/termcap itself. rxvt-unicode termcap entry is broken on its own since it needs tc=rxvt to function correctly, and there's no rxvt-256color entry. Additionally, x11/rxvt-unicode should change the default hardcoded termName if XTERM_COLOR is defined, and at no point should it allow using the default rxvt termcap entry since it needs to include rxvt-unicode functionality.
 
Back
Top