How to print text using any one of the 256 colors that the terminal allows

colorsterminal

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?

Best Answer

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.: