11

I'm having trouble getting 256 colors to work using emacs 23.1.1 connecting using PuTTY and screen. Server is running CentOS 5.6.

In my PuTTY config, my terminal-type string is set to xterm-256color. In my .screenrc I have term xterm-256color Once in screen tput colors gives me 256, echo $TERM gives me xterm-256color, but once I start emacs M-x list-colors-display only gives me 8 colors.

Not sure what the problem is.

Thanks.

Justin Schell
  • 111
  • 1
  • 4
  • I guess I should mention that I had 256 colors working on another server running CentOS 4.5, but have migrated to a new server running CentOS 5.6. I copied my .emacs and .screenrc from the first server to the second. Maybe this points to a problem with CentOS 5.6. – Justin Schell Apr 10 '12 at 19:47
  • Also, if I just connect to the server and run emacs without starting a screen session, `M-x list-colors-display` lists more colors, but the ones after the first 8 are shown in the normal foreground and background colors (white and black), not the listed colors. – Justin Schell Apr 10 '12 at 19:50
  • Does anything in http://stackoverflow.com/a/7629752/391315 help? – vhallac Apr 13 '12 at 16:26

7 Answers7

5

I hit the same problem.

To fix this problem, just add this to ~/.bashrc (yes,I use bash)

# -----------
export TERM=xterm-256color
export TERMCAP=
# ------------

run screen and emacs in an screen window. it's ok now.

versions:

bash-4.2.45

emacs-24.3_10

Screen version 4.00.03 (FAU) 23-Oct-06

pubby
  • 59
  • 1
  • 2
4

Your ~/.screenrc should read:

term screen-256color

(this shouldn't be mixed up with xterm-256color)

Hartmut Pfarr
  • 5,534
  • 5
  • 36
  • 42
1

Putty has a setting to allow 256 color mode. It's under Window/Colours, labeled "Allow terminal to use xterm 256-colour mode". Make sure it's checked.

After you load emacs, you can confirm the TERM value emacs is using with:

(assoc 'tty-type (frame-parameters (car (frame-list))))

It should be (tty-type . "xterm-256color").

ataylor
  • 64,891
  • 24
  • 161
  • 189
1

Looking at your post and your responses to others, it sounds like your problem is... screen. To test my hypothesis, try this ...

$ wget http://www.frexx.de/xterm-256-notes/data/256colors2.pl
$ chmod 755 256colors2.pl
$ ./256colors2.pl

... if you see 256 colors in the shell, but not in screen, the problem is screen. And, even if there are other problems, you are going to have to fix screen in order to have any hope of seeing 256 colors in emacs ;)

I recently fixed this situation for myself on a system where I don't have sudo by building a personal copy of screen. Screen is small and it is no big deal to do ... and, IMHO, emacs w/256 colors is well worth the bother.

On Linux 2.6.x I did this:

$ wget ftp://ftp.gnu.org/gnu/screen/screen-4.0.3.tar.gz 
$ tar -xf screen-4.0.3.tar.gz
$ cd screen-4.0.3
$ ./configure --prefix=$HOME --enable-colors256
$ make
$ make install 

Test the new screen out with ...

$ ~/bin/screen
$ ./256colors2.pl

... if it works, put this in your ~/.bashrc:

PATH=~/bin:$PATH ; export PATH

The screen I ended up with reports being an earlier version ...

$ ~/bin/screen -v
Screen version 4.01.00devel (GNUdf0777e) 2-May-06

... than the version on my system:

$ /usr/local/bin/screen -v
Screen version 4.00.03 (FAU) 23-Oct-06

But while they both claim to support 256 colors...

$ tput colors 
256

Only the new build really does. Yeah!

myglc2
  • 431
  • 1
  • 4
  • 6
0

I had similar difficulties, I believe both of these lines were required for screen, putty, and emacs to get along with 256 colors.

termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
term xterm-256color

You may also need this line too.

defbce "on"

Speak up if that's still not enough.

Eric Johnson
  • 696
  • 4
  • 23
  • 1
    Thanks, but I already had all of those lines in my .screenrc. – Justin Schell Apr 10 '12 at 19:42
  • A couple of random suggestions. Check out items #1 and #2 [here][http://emacswiki.org/emacs/PuTTY#toc2]. The ncurses-term suggestion feels familiar to me. I may have had to do that myself to make my own setup works. But the details elude me now. If that doesn't work, consider trying out tmux to see if that would at least be made to work. I can appreciate if you don't want to make the switch, but fiddling with tmux may show the way to a working screen configuration. – Eric Johnson Apr 10 '12 at 22:25
0

Try using emacs in daemon mode instead (emacs --daemon), and open emacsclients (emacsclient -t) instead of using screen/tmux. This will give you one less variable to handle in debugging this.

monotux
  • 3,657
  • 28
  • 30
0

I was having a similar problem with putty and screen, though not using emacs. Following ataylor's response, I went to Window/Colours in Putty. In there I found and checked 'Use system colours'. This fixed my issue.

Doug Noel
  • 684
  • 4
  • 19