Start The Book of Colors

This commit is contained in:
The Magician 2023-11-04 21:45:56 +00:00
parent e06ce5a2bd
commit ea40090dd9
2 changed files with 148 additions and 91 deletions

91
termcol
View File

@ -1,91 +0,0 @@
#!/bin/sh
set -e
clear
printf '\e[4;37m\e[7;36mA Book of Colors\e[0m\n'
printf '\n'
printf 'Use \\e (or \\033) followed by the control sequence specified next to activate that color.\n'
printf 'Use the reset sequence "[0m" to remove all set colors and styles.\n'
printf 'When using these sequences in a Bash prompt (e.g. $PS1), be sure to surround the whole escape sequence with escaped brackets to prevent issues with Bash miscounting the number of characters in a line. For example: `export PS1=''\[\\e[36m\]\u@\h \$\[\\e[0m\]''` would create a cyan-colored prompt string.\n'
printf '\n'
printf '\e[4;37m\e[1;37mRegular Colors\e[0m\n'
printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
printf '\e[30m[30m Black\e[0m \e[40m[40m Black\e[0m\n'
printf '\e[31m[31m Red\e[0m \e[41m[41m Red\e[0m\n'
printf '\e[32m[32m Green\e[0m \e[42m[42m Green\e[0m\n'
printf '\e[33m[33m Brown\e[0m \e[43m[43m Brown\e[0m\n'
printf '\e[34m[34m Blue\e[0m \e[44m[44m Blue\e[0m\n'
printf '\e[35m[35m Purple\e[0m \e[45m[45m Purple\e[0m\n'
printf '\e[36m[36m Cyan\e[0m \e[46m[46m Cyan\e[0m\n'
printf '\e[37m[37m Light grey\e[0m \e[47m[47m Light grey\e[0m\n'
printf '\n'
printf '\e[4;37m\e[1;37mExtra Attributes\e[0m\n'
printf 'Extra attributes can be given by placing a numeric value (representing the attribute) followed by a '';'' after the ''['' character.\n'
printf '\n'
printf '\e[4;37m\e[1;37m1; (Boldness)\e[0m\n'
printf 'Note that some terminals use the "bold" attribute to display an alternate version of the color, e.g. a lighter or darker shade.\n'
printf 'The canonical names for these alternate colors are what is displayed below.\n'
printf 'Other terminals actually support displaying text with this attribute in a bold typeface.\n'
printf '\n'
printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
printf '\e[1;30m[1;30m Dark grey\e[0m \e[1;40m[1;40m Dark grey\e[0m\n'
printf '\e[1;31m[1;31m Light red\e[0m \e[1;41m[1;41m Light red\e[0m\n'
printf '\e[1;32m[1;32m Light green\e[0m \e[1;42m[1;42m Light green\e[0m\n'
printf '\e[1;33m[1;33m Yellow\e[0m \e[1;43m[1;43m Yellow\e[0m\n'
printf '\e[1;34m[1;34m Light blue\e[0m \e[1;44m[1;44m Light blue\e[0m\n'
printf '\e[1;35m[1;35m Light purple\e[0m \e[1;45m[1;45m Light purple\e[0m\n'
printf '\e[1;36m[1;36m Light cyan\e[0m \e[1;46m[1;46m Light cyan\e[0m\n'
printf '\e[1;37m[1;37m White\e[0m \e[1;47m[1;47m White\e[0m\n'
printf '\n'
printf '\e[4;37m\e[1;37m4; (Underscore)\e[0m\n'
printf 'This attribute displays text with an underline.\n'
printf 'If the underline is always displayed in the foreground color. See the table below for more detail.\n'
printf '\n'
printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
printf '\e[4;30m[4;30m Black\e[0m \e[4;40m[4;40m Black\e[0m\n'
printf '\e[4;31m[4;31m Red\e[0m \e[4;41m[4;41m Red\e[0m\n'
printf '\e[4;32m[4;32m Green\e[0m \e[4;42m[4;42m Green\e[0m\n'
printf '\e[4;33m[4;33m Brown\e[0m \e[4;43m[4;43m Brown\e[0m\n'
printf '\e[4;34m[4;34m Blue\e[0m \e[4;44m[4;44m Blue\e[0m\n'
printf '\e[4;35m[4;35m Purple\e[0m \e[4;45m[4;45m Purple\e[0m\n'
printf '\e[4;36m[4;36m Cyan\e[0m \e[4;46m[4;46m Cyan\e[0m\n'
printf '\e[4;37m[4;37m Light grey\e[0m \e[4;47m[4;47m Light grey\e[0m\n'
printf '\n'
printf '\e[4;37m\e[1;37m5; (Blinkentext)\e[0m\n'
printf 'Also known as the dreaded blinking text of doom.\n'
printf 'Causes text to blink. Some terminal emulators refuse to honor this attribute as a matter of good taste, although there are some semi-legitimate uses for it -- the `ls` program, for example, can be configured to cause listings of broken symlinks to blink.\n'
printf 'Note that even if the blinking attribute is set on a background color, it''s always the text that blinks, not the background.\n'
printf '\n'
printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
printf '\e[5;30m[5;30m Black\e[0m \e[5;40m[5;40m Black\e[0m\n'
printf '\e[5;31m[5;31m Red\e[0m \e[5;41m[5;41m Red\e[0m\n'
printf '\e[5;32m[5;32m Green\e[0m \e[5;42m[5;42m Green\e[0m\n'
printf '\e[5;33m[5;33m Brown\e[0m \e[5;43m[5;43m Brown\e[0m\n'
printf '\e[5;34m[5;34m Blue\e[0m \e[5;44m[5;44m Blue\e[0m\n'
printf '\e[5;35m[5;35m Purple\e[0m \e[5;45m[5;45m Purple\e[0m\n'
printf '\e[5;36m[5;36m Cyan\e[0m \e[5;46m[5;46m Cyan\e[0m\n'
printf '\e[5;37m[5;37m Light grey\e[0m \e[5;47m[5;47m Light grey\e[0m\n'
printf '\n'
printf '\e[4;37m\e[1;37m7; (Inverse)\e[0m\n'
printf 'Causes the foreground and background text to be flipped.\n'
printf 'This is mostly a convenient shorthand for avoiding setting the foreground and background text simultaneously when you want one to be the default of the other.\n'
printf '\n'
printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
printf '\e[7;30m[7;30m Black\e[0m \e[7;40m[7;40m Black\e[0m\n'
printf '\e[7;31m[7;31m Red\e[0m \e[7;41m[7;41m Red\e[0m\n'
printf '\e[7;32m[7;32m Green\e[0m \e[7;42m[7;42m Green\e[0m\n'
printf '\e[7;33m[7;33m Brown\e[0m \e[7;43m[7;43m Brown\e[0m\n'
printf '\e[7;34m[7;34m Blue\e[0m \e[7;44m[7;44m Blue\e[0m\n'
printf '\e[7;35m[7;35m Purple\e[0m \e[7;45m[7;45m Purple\e[0m\n'
printf '\e[7;36m[7;36m Cyan\e[0m \e[7;46m[7;46m Cyan\e[0m\n'
printf '\e[7;37m[7;37m Light grey\e[0m \e[7;47m[7;47m Light grey\e[0m\n'

148
thebookofcolors Executable file
View File

@ -0,0 +1,148 @@
#!/bin/sh
set -e
thebookofcolors() {
printf '\e[4;7;36m'
if test -z "$1"; then
printf 'The Book of Colors'
else
printf "$1"
fi
printf '\e[0m'
}
newline() {
if test -z "$1"; then
printf '\n'
return
fi
for i in $(seq 1 $1); do
printf '\n'
done
}
title() {
if test -z "$1"; then
printf "No title provided." 1>&2
exit 1
fi
printf '\e[1;4;37m'
printf "$1"
printf '\e[0m\n'
}
main() {
clear
thebookofcolors
newline 2
title "Introduction"
thebookofcolors
printf ' is an in-terminal manual on ANSI escape codes, or "color codes", for use in terminal emulators.\n'
printf 'Examples are given not only in written form, but "practical" form -- every escape code and option described in '
thebookofcolors
printf ' is used in '
thebookofcolors "The Book"
printf ' itself.\n'
#printf 'Use \\e (or \\033) followed by the control sequence specified next to activate that color.\n'
#printf 'Use the reset sequence "[0m" to remove all set colors and styles.\n'
#printf 'When using these sequences in a Bash prompt (e.g. $PS1), be sure to surround the whole escape sequence with escaped brackets to prevent issues with Bash miscounting the number of characters in a line. For example: `export PS1=''\[\\e[36m\]\u@\h \$\[\\e[0m\]''` would create a cyan-colored prompt string.\n'
#printf '\n'
#
#printf '\e[4;37m\e[1;37mRegular Colors\e[0m\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[30m[30m Black\e[0m \e[40m[40m Black\e[0m\n'
#printf '\e[31m[31m Red\e[0m \e[41m[41m Red\e[0m\n'
#printf '\e[32m[32m Green\e[0m \e[42m[42m Green\e[0m\n'
#printf '\e[33m[33m Brown\e[0m \e[43m[43m Brown\e[0m\n'
#printf '\e[34m[34m Blue\e[0m \e[44m[44m Blue\e[0m\n'
#printf '\e[35m[35m Purple\e[0m \e[45m[45m Purple\e[0m\n'
#printf '\e[36m[36m Cyan\e[0m \e[46m[46m Cyan\e[0m\n'
#printf '\e[37m[37m Light grey\e[0m \e[47m[47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37mExtra Attributes\e[0m\n'
#printf 'Extra attributes can be given by placing a numeric value (representing the attribute) followed by a '';'' after the ''['' character.\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m1; (Boldness)\e[0m\n'
#printf 'Note that some terminals use the "bold" attribute to display an alternate version of the color, e.g. a lighter or darker shade.\n'
#printf 'The canonical names for these alternate colors are what is displayed below.\n'
#printf 'Other terminals actually support displaying text with this attribute in a bold typeface.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[1;30m[1;30m Dark grey\e[0m \e[1;40m[1;40m Dark grey\e[0m\n'
#printf '\e[1;31m[1;31m Light red\e[0m \e[1;41m[1;41m Light red\e[0m\n'
#printf '\e[1;32m[1;32m Light green\e[0m \e[1;42m[1;42m Light green\e[0m\n'
#printf '\e[1;33m[1;33m Yellow\e[0m \e[1;43m[1;43m Yellow\e[0m\n'
#printf '\e[1;34m[1;34m Light blue\e[0m \e[1;44m[1;44m Light blue\e[0m\n'
#printf '\e[1;35m[1;35m Light purple\e[0m \e[1;45m[1;45m Light purple\e[0m\n'
#printf '\e[1;36m[1;36m Light cyan\e[0m \e[1;46m[1;46m Light cyan\e[0m\n'
#printf '\e[1;37m[1;37m White\e[0m \e[1;47m[1;47m White\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m2; (Test)\e[0m\n'
#printf '\e[2;34m[2;34m Light blue\e[0m \e[2;44m[2;44m Light blue\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m3; (Test)\e[0m\n'
#printf '\e[3;34m[3;34m Light blue\e[0m \e[3;44m[3;44m Light blue\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m4; (Underscore)\e[0m\n'
#printf 'This attribute displays text with an underline.\n'
#printf 'If the underline is always displayed in the foreground color. See the table below for more detail.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[4;30m[4;30m Black\e[0m \e[4;40m[4;40m Black\e[0m\n'
#printf '\e[4;31m[4;31m Red\e[0m \e[4;41m[4;41m Red\e[0m\n'
#printf '\e[4;32m[4;32m Green\e[0m \e[4;42m[4;42m Green\e[0m\n'
#printf '\e[4;33m[4;33m Brown\e[0m \e[4;43m[4;43m Brown\e[0m\n'
#printf '\e[4;34m[4;34m Blue\e[0m \e[4;44m[4;44m Blue\e[0m\n'
#printf '\e[4;35m[4;35m Purple\e[0m \e[4;45m[4;45m Purple\e[0m\n'
#printf '\e[4;36m[4;36m Cyan\e[0m \e[4;46m[4;46m Cyan\e[0m\n'
#printf '\e[4;37m[4;37m Light grey\e[0m \e[4;47m[4;47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m5; (Blinkentext)\e[0m\n'
#printf 'Also known as the dreaded blinking text of doom.\n'
#printf 'Causes text to blink. Some terminal emulators refuse to honor this attribute as a matter of good taste, although there are some semi-legitimate uses for it -- the `ls` program, for example, can be configured to cause listings of broken symlinks to blink.\n'
#printf 'Note that even if the blinking attribute is set on a background color, it''s always the text that blinks, not the background.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[5;30m[5;30m Black\e[0m \e[5;40m[5;40m Black\e[0m\n'
#printf '\e[5;31m[5;31m Red\e[0m \e[5;41m[5;41m Red\e[0m\n'
#printf '\e[5;32m[5;32m Green\e[0m \e[5;42m[5;42m Green\e[0m\n'
#printf '\e[5;33m[5;33m Brown\e[0m \e[5;43m[5;43m Brown\e[0m\n'
#printf '\e[5;34m[5;34m Blue\e[0m \e[5;44m[5;44m Blue\e[0m\n'
#printf '\e[5;35m[5;35m Purple\e[0m \e[5;45m[5;45m Purple\e[0m\n'
#printf '\e[5;36m[5;36m Cyan\e[0m \e[5;46m[5;46m Cyan\e[0m\n'
#printf '\e[5;37m[5;37m Light grey\e[0m \e[5;47m[5;47m Light grey\e[0m\n'
#printf '\n'
#printf '\e[4;37m\e[1;37m7; (Inverse)\e[0m\n'
#printf 'Causes the foreground and background text to be flipped.\n'
#printf 'This is mostly a convenient shorthand for avoiding setting the foreground and background text simultaneously when you want one to be the default of the other.\n'
#printf '\n'
#printf '\e[4;37mForeground\e[0m \e[4;37mBackground\e[0m\n'
#printf '\e[7;30m[7;30m Black\e[0m \e[7;40m[7;40m Black\e[0m\n'
#printf '\e[7;31m[7;31m Red\e[0m \e[7;41m[7;41m Red\e[0m\n'
#printf '\e[7;32m[7;32m Green\e[0m \e[7;42m[7;42m Green\e[0m\n'
#printf '\e[7;33m[7;33m Brown\e[0m \e[7;43m[7;43m Brown\e[0m\n'
#printf '\e[7;34m[7;34m Blue\e[0m \e[7;44m[7;44m Blue\e[0m\n'
#printf '\e[7;35m[7;35m Purple\e[0m \e[7;45m[7;45m Purple\e[0m\n'
#printf '\e[7;36m[7;36m Cyan\e[0m \e[7;46m[7;46m Cyan\e[0m\n'
#printf '\e[7;37m[7;37m Light grey\e[0m \e[7;47m[7;47m Light grey\e[0m\n'
}
name="$(basename $0)"
if test "$name" = "thebookofcolors"; then
main
fi