MacOS – Running GNU Screen with 256 colors on OS X Lion

emacsmacos

Terminal.app in Mac OS X Lion has a feature that took a long time to get implemented: 256 color support. The colors work fine. The issue I'm having is that when I run GNU Screen I do not have access to 256 colors. In screen, $TERM is set to "screen".

I've read different things in different places and am very confused. Some of these include:

  • GNU Screen must be compiled with color support (How can I tell if OS X's screen was compiled this way?)
  • A special terminfo file for screen-256color must be installed. Does OS X have this?
  • In .screenrc, term should be set to "screen-256color".
  • Certain functions in Emacs must be called for Emacs to be colorful (http://www.emacswiki.org/emacs/GnuScreen#toc6)

I tried variations of these procedures and have been unsuccessful and uncertain of why I have failed. What is the most direct way for me to enable 256 colors in GNU Screen?

Best Answer

By default, screen is not aware that it is running in a 256-color-capable xterm. To make programs in screen recognize this feature, you need to set a couple of things in your ~/.screenrc:

term "screen-256color"
# terminfo and termcap for nice 256 color terminal
# allow bold colors - necessary for some reason
attrcolor b ".I" 
# tell screen how to set colors. AB = background, AF=foreground 
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm' 
# erase background with current bg color 
defbce "on" 

If this doesn’t work for you, your version of screen probably wasn’t compiled with ./configure --enable-colors256. You can check this in the welcome screen when starting screen. The default version that comes with OS X doesn’t support 256 colors. You could check out the source and compile your own version, putting the resulting binary in your $PATH (I put it in ~/bin which I added to my $PATH):

git clone git://git.savannah.gnu.org/screen.git
cd screen/src
./autogen.sh
./configure --enable-colors256
make   # I got a lot of warnings here, but they don't seem to matter
sudo make install
cp screen ~/bin/screen

Sources: 1 and 2