Refactor ansi-colours, add argument to only print 8 colours
This commit is contained in:
parent
5ce626bb46
commit
bdd3a88cba
@ -1,36 +1,49 @@
|
||||
#!/usr/bin/env zsh
|
||||
# Prints ANSI colours along with their escape codes.
|
||||
# Prints ANSI colours along with their escape codes. Let the first argument be
|
||||
# 8 to limit output to classic colours.
|
||||
# https://tintin.mudhalla.net/info/256color/
|
||||
# https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009
|
||||
|
||||
print "\e[1;97mClassic colours:\e[0m"
|
||||
print "Regular Bold Underline Background"
|
||||
for n in {30..37}; 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" \
|
||||
"\e[4;${n}m\\\e[4;${n}m\e[m" "\e[${nbg}m\\\e[${nbg}m\e[m"
|
||||
done
|
||||
function _ansi-colors_8()
|
||||
{
|
||||
local title="${1}"
|
||||
local start="${2}"
|
||||
|
||||
print "\n\e[1;97mHigh intensity colours:\e[0m"
|
||||
print "Regular Bold Underline Background"
|
||||
for n in {90..97}; 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" \
|
||||
"\e[4;${n}m\\\e[4;${n}m\e[m" "\e[${nbg}m\\\e[${nbg}m\e[m"
|
||||
done
|
||||
print "\e[1;97m${title}\e[0m:"
|
||||
print "Regular Bold Underline Backgr. Dim Reversed Blinking"
|
||||
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" \
|
||||
"\e[4;${n}m\\\e[4;${n}m\e[m" "\e[${nbg}m\\\e[${nbg}m\e[m" \
|
||||
"\e[2;${n}m\\\e[2;${n}m\e[m" "\e[7;${n}m\\\e[7;${n}m\e[m" \
|
||||
"\e[5;${n}m\\\e[5;${n}m\e[m"
|
||||
done
|
||||
}
|
||||
|
||||
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}
|
||||
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}
|
||||
|
||||
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"
|
||||
print "\e[1;97mReset:\e[0m \\\e[0m"
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user