Script to display all terminal colors

Solution 1:

Here is my solution with Bash only:

for x in {0..8}; do 
    for i in {30..37}; do 
        for a in {40..47}; do 
            echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "
        done
        echo
    done
done
echo ""

One-liner:

for x in {0..8}; do for i in {30..37}; do for a in {40..47}; do echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "; done; echo; done; done; echo ""

Here's a picture in Cygwin:

Cygwin screenshot

Solution 2:

A simple one-liner that should work for most people.

msgcat --color=test

Solution 3:

You can also use the colortest Install colortest package.

  1. Install it with this command:

    sudo apt-get install colortest
    
  2. It provides several commands which you can use, depending on how many colors you want:

    colortest-16   colortest-16b  colortest-256  colortest-8
    

Example output from colortest-16b:

enter image description here

Solution 4:

Here's my version:

#!/usr/bin/env python
import sys
terse = "-t" in sys.argv[1:] or "--terse" in sys.argv[1:]
write = sys.stdout.write
for i in range(2 if terse else 10):
    for j in range(30, 38):
        for k in range(40, 48):
            if terse:
                write("\33[%d;%d;%dm%d;%d;%d\33[m " % (i, j, k, i, j, k))
            else:
                write("%d;%d;%d: \33[%d;%d;%dm Hello, World! \33[m \n" %
                      (i, j, k, i, j, k,))
        write("\n")

This prints everything. If you want a nice table (that only shows style (0) and (1), normal and bold), you can use the -t or --terse argument:

The 'blink' style (5) doesn't work with gnome-terminal. ;-)


If this doesn't work for you, there's something else wrong. Please let us know once you've tested it.