Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to write a program that utilizes all 256 of the Linux terminal's text colors. To date, however, I have only found a handful of color codes, which are in the format "\033[1;NUMmNUM\033[1;m". However, these escape codes only allow for two or three dozen colors, not the 256 that the Linux terminal supposedly allows for. How can I display those other colors in my curses application?

share|improve this question

2 Answers 2

Stop using escape codes and use the setaf terminfo capability instead.

$ for i in $(seq 0 $(tput colors) ) ; do tput setaf $i ; echo -n "█" ; done ; tput setaf 15 ; echo
share|improve this answer
    
I only get eight colors that way, though, and the terminal supposedly supports 256. Where did all of the other colors go? –  InkBlend Jun 12 '13 at 4:53
    
Your terminal only supports 8 colors then. Try another terminal. –  Ignacio Vazquez-Abrams Jun 12 '13 at 4:54
    
I have tried LXTerm, Xterm, and the Linux terminal (both with and without tmux), and gotten the same result on all three. Are you sure that the Linux ttys themselves do not support 256 colors? –  InkBlend Jun 12 '13 at 5:07
    
tput colors on my console resulted in 8. So I would say that this is not unique to you. –  Ignacio Vazquez-Abrams Jun 12 '13 at 5:21

You can have a look into TERM settings. It is possible it is set to lesser then capable string. To test colors you can run GNU's msgcat. Try e.g.:

echo $TERM
msgcat --color=test
TERM=xterm-256color
msgcat --color=test

Or use @Ignacio Vazquez-Abrams's loop instead of msgcat.

For more information on how and what to set have a look at e.g.:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.