Created
July 18, 2026 17:49
-
-
Save wg1k/736003e81f3e3f8d96eb2493a72aa5ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fg_for() { | |
| local c=$1 r g b | |
| if (( c < 16 )); then | |
| case $c in | |
| 0|8) r=0; g=0; b=0 ;; | |
| 1|9) r=255; g=0; b=0 ;; | |
| 2|10) r=0; g=255; b=0 ;; | |
| 3|11) r=255; g=255; b=0 ;; | |
| 4|12) r=0; g=0; b=255 ;; | |
| 5|13) r=255; g=0; b=255 ;; | |
| 6|14) r=0; g=255; b=255 ;; | |
| 7|15) r=255; g=255; b=255 ;; | |
| esac | |
| elif (( c < 232 )); then | |
| local n=$((c - 16)) ri gi bi | |
| local levels=(0 95 135 175 215 255) | |
| ri=$((n / 36)); gi=$(((n / 6) % 6)); bi=$((n % 6)) | |
| r=${levels[ri]}; g=${levels[gi]}; b=${levels[bi]} | |
| else | |
| r=$(( (c - 232) * 10 + 8 )); g=$r; b=$r | |
| fi | |
| local lum=$(( (299*r + 587*g + 114*b) / 1000 )) | |
| (( lum > 128 )) && echo 0 || echo 15 | |
| } | |
| for c in {0..15} {16..33} {52..69} {88..105} {124..141} {160..177} {196..213} {34..51} {70..87} {106..123} {142..159} {178..195} {214..231} {232..249} {250..255}; do | |
| tput setab "${c}" | |
| tput setaf "$(fg_for "${c}")" | |
| tput bold | |
| printf '%3s ' "${c}" | |
| tput sgr0 | |
| if [ 15 -eq $((c%18)) ]; then echo; fi | |
| done |
wg1k
commented
Jul 18, 2026
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment