Getting 256 colors out of ruby-ncurses
Asked Answered
E

3

8

I've got 256 colors working great in my terminal (test scripts here), but it stops working when I use ncurses (via Ruby-ncurses). Printing the escape sequences given on that page works fine, but when I initialize ncurses 'puts' stops working and I can't output the colors with any of the various ncurses color changing/string output functions I've found. What gives?

Exegete answered 5/10, 2008 at 4:33 Comment(0)
E
5

njsf: You were partially right here, and after tinkering a lot more I eventually got it to work. Thanks for your help. The story: XTerm (and rxvt, and Eterm) support 256 colors via escape sequences (what I was seeing) but 'tput colors' will say '8' and ncurses won't be able to get at them, because ncurses is playing nice and attempting to access via terminfo.

For the benefit of anyone with similar pain:

I found I need to install the ncurses-term (Ubuntu) package to get /lib/terminfo/x/xterm-256color and other 256-color terminfo files. Then I set my TERM to xterm-256color and added the line '*customization: -color' to my ~/.Xdefaults, ran 'xrdb -merge ~/.Xdefaults' to load it, and from then on I have proper 256 color support in new xterms.

Exegete answered 5/10, 2008 at 22:18 Comment(1)
Yep, came here to suggest setting your terminal properly.. Also a tid-bit for any drive-by readers. Mac OS X Terminal.app for example only supports 16 colors, so you either use iTerm, or XTerm on X11 or forget it!Chrisy
N
7

I am not sure if this would be all the story, but make sure your terminal capabilities do indeed provide for the 256 colors description.

What is the TERM environment variable value? Try setting it to xterm-256color and rerun it. ncurses should then get the proper color escape sequences.

You can also test the terminal capabilities and terminal color output with the program we use at SXEmacs development:

http://www.triatlantico.org/tmp/tty-colors.c

Compile with gcc -o tty-colors tty-colors.c -lncurses

EDIT: Note that just because the scripts that are found on the net output the 256 colors, that is not "all set". Curses programs rely on terminfo and termcap and the TERM environment variable to find out how to interact with the terminal. So in order for a curses app to be able to use the 256 colors one should set the TERM variable to an existing terminal name which supports 256 colors. The C program above will show you what ncurses thinks about your terminal, not just output the xterm sequences like most scripts do [even the one from X.org]

Nels answered 5/10, 2008 at 4:42 Comment(0)
E
5

njsf: You were partially right here, and after tinkering a lot more I eventually got it to work. Thanks for your help. The story: XTerm (and rxvt, and Eterm) support 256 colors via escape sequences (what I was seeing) but 'tput colors' will say '8' and ncurses won't be able to get at them, because ncurses is playing nice and attempting to access via terminfo.

For the benefit of anyone with similar pain:

I found I need to install the ncurses-term (Ubuntu) package to get /lib/terminfo/x/xterm-256color and other 256-color terminfo files. Then I set my TERM to xterm-256color and added the line '*customization: -color' to my ~/.Xdefaults, ran 'xrdb -merge ~/.Xdefaults' to load it, and from then on I have proper 256 color support in new xterms.

Exegete answered 5/10, 2008 at 22:18 Comment(1)
Yep, came here to suggest setting your terminal properly.. Also a tid-bit for any drive-by readers. Mac OS X Terminal.app for example only supports 16 colors, so you either use iTerm, or XTerm on X11 or forget it!Chrisy
C
2

setting

ENV['TERM'] += '-256color' if ENV['TERM'] == 'xterm' # activate 256 colors

works on ubuntu 10.04 +

Costrel answered 14/9, 2011 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.