ANSI Colors on console term
Depending on wich term protocol your console use, sequence could be: \e[38;5;XXXm or \e[3XXXm where XXX correspond to ansi number.
To ensure you use the right ANSI sequence, you have to use tput.
Regarding to Wikipedia's ANSI escape code, I wrote this:
#!/bin/bash for ((i=0; i<256; i++)) ;do echo -n ' ' tput setab $i tput setaf $(( ( (i>231&&i<244 ) || ( (i<17)&& (i%8<2)) || (i>16&&i<232)&& ((i-16)%6 <(i<100?3:2) ) && ((i-16)%36<15) )?7:16)) printf " C %03d " $i tput op (( ((i<16||i>231) && ((i+1)%8==0)) || ((i>16&&i<232)&& ((i-15)%6==0)) )) && printf "\n" '' done Could render something like:
... Then, because I hate runnig more than 200 forks in a little script, I wrote this:
#!/bin/bash # Connector fifos directory read TMPDIR < <(mktemp -d /dev/shm/bc_shell_XXXXXXX) fd=3 # find next free fd nextFd() { while [ -e /dev/fd/$fd ];do ((fd++)) ;done;printf -v $1 %d $fd;} tputConnector() { mkfifo $TMPDIR/tput nextFd TPUTIN eval "exec $TPUTIN> >(LANG=C exec stdbuf -o0 tput -S - >$TMPDIR/tput 2>&1)" nextFd TPUTOUT eval "exec $TPUTOUT<$TMPDIR/tput" } myTput() { echo -e "$1\ncr" 1>&$TPUTIN && IFS= read -r -d $'\r' -u $TPUTOUT $2 } tputConnector myTput op op myTput "setaf 7" grey myTput "setaf 16" black fore=("$black" "$grey") for ((i=0; i<256; i++)) ;do myTput "setab $i" bgr printf " %s%s %3d %s" "$bgr" "${fore[ i>231 && i<244||(i<17)&& (i%8<2)|| (i>16&&i<232)&&((i-16)%6*11+(i-16)/6%6*14+(i-16)/36*10)<58 ? 1 : 0 ]}" $i "$op" (( ((i<16||i>231) && ((i+1)%8==0)) || ((i>16&&i<232)&& ((i-15)%6==0)) )) && printf "\n" '' done With only 1 fork! Same result, but a lot quicker!
