XTerm Color Count
Count how many colors your XTerm actually supports, since it may be different from what
tput colors reports.
For example, both gnome-terminal and XTerm support 256 colors, but
tput colors returns 8.
You might have to wait a few seconds for the result to be returned.
Print each color number and show what it looks like.
Show all the colors, like -v, but use a given number instead of the count.
- This does not work with the Linux console as it does not support the OSC 4 escape sequence. Instead the script falls back to
tput colorswhich uses the terminfo file.
It is a mystery why the default terminfo for XTerm and gnome-terminal lie about how many colors they have. You can "fix" it so
tput colorsreturns the proper result by using
export TERM=xterm-256color. Some applications (such as emacs in a terminal window) will use the extra colors. For example, try,
TERM=xterm-256color emacs -nw -f list-colors-display -f delete-window
A 256 color XTerm has this color mapping
- System colors: 0 to 15
- Grayscale: 232 to 255 (note, black and white intentionally omitted)
- 6x6x6 color cube: 16-231 (For R,G,B between 0 and 5,
color-index = 16 + R×6×6 + G×6 + B)
L0b0 wrote the code, hackerb9 changed it to a binary search. Gilles did all the research, and has awesome communication skills and *nix knowledge.