#!/bin/bash # # output all 256 colors supported by the ANSI terminal expansion # # The 256 colors are arranged in 3 groups... # # 16 System Colors codes 0 to 15 (standard, then hi-intensity) # 6x6x6 Color Cube codes 16 to 231 (16 + r*36 + g*6 + b, for values 0-5) # a greyscale ramp codes 232 to 255 (24 step greysacle, exclude min/max) # # and are used using "\e[38;5;${code}m" for the foreground color # and are used using "\e[48;5;${code}m" for the background color # # Some terminals allow you to specify the nearest color to RGB values # (including xterm and konsole) "\e[38;2;$R;$G;$B" # # XTERM color settings in the 6x6x6 cube is not particularly well defined # e=$'\e' # Escape character F=$'\e[0;38;5;%dm' # set background color and output two spaces B=$'\e[0;48;5;%dm' # set background color and output two spaces N=$'\e[0m' # reset to normal echo "For 8-bit color table Xterms..." echo " \$'\e[48;5;{color}m' to set background color" echo " \$'\e[38;5;{color}m' to set the foreground color" echo "For direct 24-bit color Xterms (from 2019)..." echo " \$'\e[38;2;{R};{G};{B}m' to set a specific RGB color" echo "Reset color (as always)..." echo " \$'\e[0m' to return to normal" echo "" echo "" echo "System Colors: (codes 0 to 15)" for j in `seq 0 1`; do for i in `seq 0 7`; do c=$((i+j*8)) printf "$B " $c done printf "$N\n" done echo "These are also available via older ANSI color codes." echo "And some are also duplicated in the color cube below." echo "NOTE: the blue is not a perfect blue in xterms!" echo "" echo "6x6x6 RGB Color Cube:" echo "using \$'\e[48;5;{color}m' color codes 16 to 231" for k in `seq 0 5`; do for j in `seq 0 5`; do for i in `seq 0 5`; do c=$((16+i+k*6+j*36)) printf "$B " $c done printf "$N " done printf "\n" done printf "\n" echo "16 shade Greyscale Ramp:" echo "using \$'\e[48;5;{color}m' color codes 232 (black) to 255 (white) )" printf "$B " 0 for i in `seq 232 255`; do printf "$B " $i done printf "$B $N\n" 15 printf "\n" echo "Rough Name Matches for colors:" printf "$B $F 36 Sea Green " 36 36; printf "$B $F 39 Light Blue " 39 39; printf "$B $F 45 Near Cyan " 45 45; printf "\n"; printf "$B $F 130 Brown " 130 130; printf "$B $F 202 Orange " 202 202; printf "$B $F 199 Hot Pink " 199 199; printf "\n"; printf "$B $F 52 Firebrick " 52 52; printf "$B $F 93 Purple " 93 93; printf "$N\n"; printf "\n"; printf "%s\n%s\n" \ 'Example compare cyan (6), with near-cyan (45), with bright cyan (14)' \ "echo \$'\\e[48;5;6m \\e[48;5;45m \\e[48;5;14m \\e[0m'" echo $'\e[48;5;6m \e[48;5;45m \e[48;5;14m \e[0m' echo