From 630d6885a1b44c17b56609ec0d16305bb04647da Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 22 May 2021 15:17:44 +0300 Subject: [PATCH] [scripts/colortest] add another script which prints color codes --- script-resources/colortest.awk | 17 +++++++++++------ scripts/colortest | 2 +- scripts/colortest2 | 2 +- scripts/colortest3 | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100755 scripts/colortest3 diff --git a/script-resources/colortest.awk b/script-resources/colortest.awk index cf66228..6f87514 100644 --- a/script-resources/colortest.awk +++ b/script-resources/colortest.awk @@ -14,20 +14,24 @@ BEGIN { print ""; } -function print_color(color) { - printf "\033[48;5;%sm \033[0m", color +function print_color(color, idx) { + if (OPT_COLOR_CODES) { + printf "\033[1;30;48;5;%sm %02X \033[0m", color, idx; + } else { + printf "\033[48;5;%sm \033[0m", color; + } } function test_standard_colors() { print "16 standard colors:"; - for (color = 0; color < 16; color += 1) print_color(color); + for (color = 0; color < 16; color += 1) print_color(color, color); print ""; } function test_base16_colorscheme() { print "base16 colorscheme:"; split("0 18 19 8 20 7 21 15 1 16 3 2 6 4 5 17", colors, " "); - for (i = 1; i <= length(colors); i++) print_color(colors[i]); + for (i = 1; i <= length(colors); i++) print_color(colors[i], i - 1); print ""; } @@ -39,7 +43,8 @@ function test_6x6x6_cube() { for (row = 0; row < 6; row++) { for (block_x = 0; block_x < block_grid_w; block_x++) { for (col = 0; col < 6; col++) { - print_color(16 + col + 6*row + 6*6*block_x + block_grid_w*6*6*block_y); + color = col + 6*row + 6*6*block_x + block_grid_w*6*6*block_y + print_color(16 + color, color); } } print ""; @@ -50,7 +55,7 @@ function test_6x6x6_cube() { function test_grayscale() { print "grayscale from black to white in 24 steps:"; for (color = 0; color < 24; color += 1) { - print_color(16 + 6*6*6 + color) + print_color(16 + 6*6*6 + color, color) } print ""; } diff --git a/scripts/colortest b/scripts/colortest index 99f0f4b..9f5bc94 100755 --- a/scripts/colortest +++ b/scripts/colortest @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -eu script_dir="$(dirname "$0")" diff --git a/scripts/colortest2 b/scripts/colortest2 index 9b685c6..8a439ff 100755 --- a/scripts/colortest2 +++ b/scripts/colortest2 @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -eu script_dir="$(dirname "$0")" cols="$(tput cols)" diff --git a/scripts/colortest3 b/scripts/colortest3 new file mode 100755 index 0000000..84a2cef --- /dev/null +++ b/scripts/colortest3 @@ -0,0 +1,7 @@ +#!/bin/sh + +set -eu + +script_dir="$(dirname "$0")" + +exec awk -v OPT_COLOR_CODES=1 -f "${script_dir}/../script-resources/colortest.awk"