Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 256 colors out of ruby-ncurses

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?

like image 862
pushcx Avatar asked Oct 05 '08 04:10

pushcx


3 Answers

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]

like image 185
njsf Avatar answered Oct 16 '22 10:10

njsf


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.

like image 45
pushcx Avatar answered Oct 16 '22 10:10

pushcx


setting

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

works on ubuntu 10.04 +

like image 39
grosser Avatar answered Oct 16 '22 10:10

grosser