2022-03-19 06:26:40 +01:00
|
|
|
#!/usr/bin/env zsh
|
2022-03-19 08:22:34 +01:00
|
|
|
# Prints ANSI colours along with their escape codes. Let the first argument be
|
|
|
|
# 8 to limit output to classic colours.
|
2022-03-19 06:59:38 +01:00
|
|
|
# https://tintin.mudhalla.net/info/256color/
|
2022-03-19 08:22:34 +01:00
|
|
|
# https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009
|
2022-03-19 06:26:40 +01:00
|
|
|
|
2022-03-19 08:22:34 +01:00
|
|
|
function _ansi-colors_8()
|
|
|
|
{
|
|
|
|
local title="${1}"
|
|
|
|
local start="${2}"
|
2022-03-19 06:26:40 +01:00
|
|
|
|
2022-03-19 08:58:54 +01:00
|
|
|
print "\e[1;97m${title}:\e[0m"
|
2022-03-19 08:48:25 +01:00
|
|
|
print "Regular Bold Underline Italic Crossed Dim Blinking Reversed Background"
|
2022-03-19 08:22:34 +01:00
|
|
|
for n in {${start}..$(( ${start}+7 ))}; do
|
|
|
|
local nbg=$(( ${n}+10 ))
|
|
|
|
print -c "\e[0;${n}m\\\e[0;${n}m\e[m" "\e[1;${n}m\\\e[1;${n}m\e[m" \
|
2022-03-19 08:48:25 +01:00
|
|
|
"\e[4;${n}m\\\e[4;${n}m\e[m" "\e[3;${n}m\\\e[3;${n}m\e[m" \
|
|
|
|
"\e[9;${n}m\\\e[9;${n}m\e[m" "\e[2;${n}m\\\e[2;${n}m\e[m" \
|
|
|
|
"\e[5;${n}m\\\e[5;${n}m\e[m" \
|
|
|
|
"\e[7;${n}m\\\e[7;${n}m\e[m" "\e[${nbg}m\\\e[${nbg}m\e[m"
|
2022-03-19 08:22:34 +01:00
|
|
|
done
|
|
|
|
}
|
2022-03-19 06:26:40 +01:00
|
|
|
|
2022-03-19 08:22:34 +01:00
|
|
|
function _ansi-colors_256()
|
|
|
|
{
|
|
|
|
print "\n\e[1;97m256 colour pallette:\e[0m"
|
|
|
|
local -a colours
|
|
|
|
for n in {0..15}; do
|
|
|
|
colours+="\e[38;5;${n}m\\\e[38;5;${n}m\e[0m"
|
|
|
|
done
|
|
|
|
print -C 2 ${colours}
|
|
|
|
colours=()
|
|
|
|
for n in {16..255}; do
|
|
|
|
colours+="\e[38;5;${n}m\\\e[38;5;${n}m\e[0m"
|
|
|
|
done
|
|
|
|
print -C 6 -a ${colours}
|
2022-03-19 06:26:40 +01:00
|
|
|
|
2022-03-19 08:22:34 +01:00
|
|
|
print "\n\e[1;97m256 colour background:\e[0m 48 instead of 38"
|
|
|
|
print "\e[1;97mTrue colour:\e[0m \\\e[38;2;\e[0;31mR\e[0m;\e[0;32mG\e[0m;\e[0;34mB\e[0mm" \
|
|
|
|
"and \\\e[48;2;\e[0;41mR\e[0m;\e[0;42mG\e[0m;\e[0;44mB\e[0mm"
|
|
|
|
}
|
|
|
|
|
|
|
|
_ansi-colors_8 "Classic colours" 30
|
|
|
|
print
|
|
|
|
_ansi-colors_8 "High intensity colours" 90
|
|
|
|
|
|
|
|
[[ -v 1 && "${1[1]}" == "8" ]] || _ansi-colors_256
|
|
|
|
|
|
|
|
print "\n\e[1;97mReset:\e[0m \\\e[0m"
|
|
|
|
unfunction _ansi-colors_8 _ansi-colors_256
|