diff --git a/bash/colors b/bash/colors new file mode 100755 index 0000000..5e397a3 --- /dev/null +++ b/bash/colors @@ -0,0 +1,34 @@ +#!/bin/bash + +# https://unix.stackexchange.com/a/269085 + +# A simple test of your console capacity to present so many colors is: +# for r in {200..255..5}; do fb=4;g=1;b=1;printf '\e[0;%s8;2;%s;%s;%sm ' "$fb" "$r" "$g" "$b"; done; echo +# It will present a red line with a very small change in tone from left to right. +# If that small change is visible, your console is capable of 16 million colors. +# If your console type support this, this code will create a color table: + +mode2header(){ + #### For 16 Million colors use \e[0;38;2;R;G;Bm each RGB is {0..255} + printf '\e[m' # reset the colors. + printf '\n\e[m%s\n' "Some samples of colors for r;g;b. Each one may be 000..255" + printf '\e[m%59s\n' "for the ansi option: \e[0;38;2;r;g;bm or \e[0;48;2;r;g;bm :" +} +mode2colors(){ + # foreground or background (only 3 or 4 are accepted) + local fb="$1" + [[ $fb != 3 ]] && fb=4 + local samples=(0 63 127 191 255) + for r in "${samples[@]}"; do + for g in "${samples[@]}"; do + for b in "${samples[@]}"; do + printf '\e[0;%s8;2;%s;%s;%sm%03d;%03d;%03d ' "$fb" "$r" "$g" "$b" "$r" "$g" "$b" + done; printf '\e[m\n' + done; printf '\e[m' + done; printf '\e[mReset\n' +} +mode2header +mode2colors 3 +mode2colors 4 + +printf '\n\e[0;38;2;255;0;0mNote\e[m: This is only a sample, all 16m colors should be available for use\e[m\n\n'