screen, 256 colours and termcap mixed with PuTTY and FreeBSD

I have a 256 colour xterm set up on my DragonFly box.

Works perfectly. Especially for vim.

Now, I use FreeBSD 5.x as a gateway box to ssh into and have irssi and likewise programs screened.

Now, I was surprised to learn that I had only 16 colours. Outside of screen I had a full 256 colour palette (make sure to fix your PuTTY configuration by the way), but inside I was stripped of my colour scheme.

So I set off to find what was causing this. Interestingly enough one of the first emails encountered was from Jeremy Chadwick who had the exact same problem.

Turns out that screen needs to be compiled with 256 colour support (a knob should be in your ports Makefile now).

Since FreeBSD’s and DragonFly’s termcap is bereft of any 256 colour definitions for xterm apparently, you need to add the following to $HOME/.screenrc:

termcap xterm* 'Co#256:AB=E[48;5;%dm:AF=E[38;5;%dm'
terminfo xterm* 'Co#256:AB=E[48;5;%p1%dm:AF=E[38;5;%p1%dm'

This overrides your termcap settings with the appropriate definitions.

If you now start screen from a shell that has TERM exported as xterm or xterm-color (xterm* wildcard actually) it will fork off to a screen with 256 colour support.

You might need this in $HOME/.vimrc:

if &term =~ "xterm" || &term =~ "screen"
  set t_Co=256
  if has("terminfo")
    let &t_Sf=nr2char(27).'[3%p1%dm'
    let &t_Sb=nr2char(27).'[4%p1%dm'
  else
    let &t_Sf=nr2char(27).'[3%dm'
    let &t_Sb=nr2char(27).'[4%dm'
  endif
endif

6 thoughts on “screen, 256 colours and termcap mixed with PuTTY and FreeBSD

  1. Thanks – the different terminfo line is key on Solaris 10 — presumably the ncurses versions are similar to yours. How did you find out that there needed to be a %p1 for terminfo but not termcap?

  2. I honestly would not know at this point, roughly six years later, why that %p1 mattered. Could be that I scrounged it from a infocmp manual page which listed %p1%d for terminfo being equivalent to %d for termcap. As for the exact technical reason, no idea anymore, sorry.

  3. I try to figure out how I can get 256 colors in screen on an FreeBSD 8.1. I got it to have 256 colors in PuTTY on the FreeBSD machine without screen. Now I installed screen with 256 color support, but unfortunately I cannot figure out what steps I have to do to get everything working in screen as well. Could you post all the steps, please? I tried to set term, termcap and terminfo in screenrc, my shell has TERM=xterm exported. But actually it does not work for me.

    I’ve a small perl script that gives me cubes with 256 colors for testing. That works perfectly when not in screen, and in screen it only shows the color codes or alternatively only 16 colors. :(

  4. Marcel, you need rebuild screen with 256-color support option, in ports /usr/ports/sysutils/screen do make config and set 256 color option, make reinstall then.
    under windows + putty I have screen-bce as term after that and yes it have 256 colors.

    I am in reverse trouble – no 256 colors anywhere except screen :-)… still googling.

  5. to be correct about my trouble – it have 256 colors, just don’t displays (maybe because of blink mode) low intensity gray command prompt, which I see in screen.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>