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-04-03 05:47:50 +02:00
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
|
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 09:12:50 +01:00
|
|
|
print "Regular Bold Underline Italic Crossed Dim Blinking Reversed"
|
2022-03-19 08:22:34 +01:00
|
|
|
for n in {${start}..$(( ${start}+7 ))}; do
|
2022-03-19 14:15:40 +01:00
|
|
|
print -c -a "\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" \
|
2022-03-19 09:12:50 +01:00
|
|
|
"\e[5;${n}m\\\e[5;${n}m\e[m" "\e[7;${n}m\\\e[7;${n}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 09:12:50 +01:00
|
|
|
print "\e[1;97mBackground:\e[0m 48 instead of 38"
|
2022-04-04 05:22:26 +02:00
|
|
|
print "Prepend 1; for bold, 3; for italic and so on (example: \e[1;3;38;5;218m\\\e[1;3;38;5;218m\e[0m)"
|
2022-03-19 09:12:50 +01:00
|
|
|
print "\n\e[1;97mTrue colour:\e[0m \\\e[38;2;\e[0;31mR\e[0m;\e[0;32mG\e[0m;\e[0;34mB\e[0mm" \
|
2022-03-19 08:22:34 +01:00
|
|
|
"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
|
2022-03-19 14:12:40 +01:00
|
|
|
print "\e[1;97mBackground:\e[0m 40-47 instead of 30-37\n"
|
2022-03-19 09:12:50 +01:00
|
|
|
|
2022-03-19 08:22:34 +01:00
|
|
|
_ansi-colors_8 "High intensity colours" 90
|
2022-03-19 09:12:50 +01:00
|
|
|
print "\e[1;97mBackground:\e[0m 100-107 instead of 90-97"
|
2022-03-19 08:22:34 +01:00
|
|
|
|
|
|
|
[[ -v 1 && "${1[1]}" == "8" ]] || _ansi-colors_256
|
|
|
|
|
|
|
|
print "\n\e[1;97mReset:\e[0m \\\e[0m"
|
|
|
|
unfunction _ansi-colors_8 _ansi-colors_256
|