Print a 256-color test pattern in the terminal

256-colour test pattern

To get the below image, use:

curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash

256-colour test pattern

The gist bash/zsh code is shellcheck clean, and also supports "Look Ma, no subprocesses!".


Alternatively, for a bash quicky:

for i in {0..255} ; do
    printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i"
    if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
        printf "\n";
    fi
done

For total overkill, the granddaddy of the lot is terminal-colors, a 572-line script with multiple output formats.

You can also print a true color (24-bit) test pattern.


I found a nice Python script for that on GitHub written by Justin Abrahms which also prints the hex codes of the colours.

Download the script to current working directory

wget https://gist.githubusercontent.com/justinabrahms/1047767/raw/a79218b6ca8c1c04856968d2d202510a4f7ec215/colortest.py

give it execute permission

chmod +x colortest.py

Run it:

./colortest.py

Here's the script in full in case of link-rot:

#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349

print "Color indexes should be drawn in bold text of the same color."
print

colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
    "%02x/%02x/%02x" % (r, g, b) 
    for r in colored
    for g in colored
    for b in colored
]

grayscale = [0x08 + 10 * n for n in range(0, 24)]
grayscale_palette = [
    "%02x/%02x/%02x" % (a, a, a)
    for a in grayscale 
]

normal = "\033[38;5;%sm" 
bold = "\033[1;38;5;%sm"
reset = "\033[0m"

for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
    index = (bold + "%4s" + reset) % (i, str(i) + ':')
    hex   = (normal + "%s" + reset) % (i, color)
    newline = '\n' if i % 6 == 3 else ''
    print index, hex, newline, 

While not quite a "test pattern", I have xterm-color-chooser:

screenshot