#!/usr/bin/env zsh # 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 function _ansi-colors_8() { local title="${1}" local start="${2}" print "\e[1;97m${title}:\e[0m" print "Regular Bold Underline Italic Crossed Dim Blinking Reversed" for n in {${start}..$(( ${start}+7 ))}; do print -c -a "\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[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" done } 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 "\e[1;97mBackground:\e[0m 48 instead of 38" 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" \ "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 "\e[1;97mBackground:\e[0m 40-47 instead of 30-37\n" _ansi-colors_8 "High intensity colours" 90 print "\e[1;97mBackground:\e[0m 100-107 instead of 90-97" [[ -v 1 && "${1[1]}" == "8" ]] || _ansi-colors_256 print "\n\e[1;97mReset:\e[0m \\\e[0m" unfunction _ansi-colors_8 _ansi-colors_256