]> git.rmz.io Git - dotfiles.git/blob - bin/colortest256
bin: add cmk
[dotfiles.git] / bin / colortest256
1 #!/bin/bash
2 # https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
3 # https://gist.github.com/XVilka/8346728#gistcomment-3528771
4
5 T='::' # The test text
6
7 function echo_block() {
8 local fs=$1
9 local bs=$2
10 echo " 01234567"
11 for (( f = 0; f < 8; f++ )); do
12 echo -en " ${f} "
13 for (( b = 0; b < 8; b++ )); do
14 echo -en "\033[38;5;$((fs+f))m\033[48;5;$((bs+b))m$T\033[0m";
15 done
16 echo
17 done
18 }
19
20 function print_colors() {
21 local c
22 for (( c = $1; c < $1 + $2; c++)); do
23 echo -en "\033[48;5;${c}m$T\033[0m"
24 done
25 echo
26 }
27 function colors() {
28 print_colors 0 8
29 print_colors 8 8
30 for (( c = 16; c < 256 - 24; c += 36 )); do
31 print_colors $c 36
32 done
33 print_colors $((256 - 24)) 24
34 }
35
36 function true_colors() {
37 awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
38 s="/\\";
39 for (colnum = 0; colnum<term_cols; colnum++) {
40 r = 255-(colnum*255/term_cols);
41 g = (colnum*510/term_cols);
42 b = (colnum*255/term_cols);
43 if (g>255) g = 510-g;
44 printf "\033[48;2;%d;%d;%dm", r,g,b;
45 printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
46 printf "%s\033[0m", substr(s,colnum%2+1,1);
47 }
48 printf "\n";
49 }'
50 }
51
52 colors
53 true_colors