l0b0 / xterm-color-count

Count how many colors your XTerm actually supports

Home Page:https://gitlab.com/victor-engmark/xterm-color-count

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Usage

./xterm-color-count.sh

You might have to wait a few seconds for the result to be returned.

./xterm-color-count.sh -v

Print each color number and show what it looks like.

./xterm-color-count.sh [number]

Show all the colors, like -v, but use a given number instead of the count.

Bugs

  • 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 colors which uses the terminfo file.

Discussion

  • 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 colors returns 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)

Credit

L0b0 wrote the code, hackerb9 changed it to a binary search. Gilles did all the research, and has awesome communication skills and *nix knowledge.

About

Count how many colors your XTerm actually supports

https://gitlab.com/victor-engmark/xterm-color-count

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%