Skip to content

Instantly share code, notes, and snippets.

@juliyvchirkov
Last active March 13, 2021 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliyvchirkov/ca7ab3522068e02d287221501ee5cd86 to your computer and use it in GitHub Desktop.
Save juliyvchirkov/ca7ab3522068e02d287221501ee5cd86 to your computer and use it in GitHub Desktop.
bash: terminal truecolor test. proof of concept, completely made of pure bash builtins
#!/usr/bin/env bash
#
# Terminal truecolor test
# Proof of concept, completely made of pure bash builtins
#
# Accepts an integer from 14 up to infinity to set the length of test snake
# By default the snake is 88 symbols long
#
# Execute or source termTestTruecolor.sh to export function
#
# termTestTrucolor
# termTestTrucolor 100
termTestTruecolor () {
local red
local green
local blue
local vga=255
local colnum=1
local maxcol=${1}
[[ ${maxcol} =~ ^[0-9]+$ && ${maxcol} -ge 14 ]] || maxcol=88
printf "\n"
while [ ${colnum} -le ${maxcol} ]
do
red=$(( vga - colnum * vga / maxcol ))
green=$(( colnum * (vga * 2) / maxcol ))
[ ${green} -gt ${vga} ] && green=$(( (vga * 2) - green ))
blue=$(( colnum * vga / maxcol ))
printf "\033[48;2;%d;%d;%dm\033[38;2;%d;%d;%dm \033[0m" \
${red} ${green} ${blue} $(( vga - red )) $(( vga - green )) $(( vga - blue ))
let colnum++
done
printf "\033[K\n\n"
}
export -f termTestTruecolor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment