Add Anatomy of an ANSI Escape Code section

This commit is contained in:
The Magician 2023-11-04 22:46:54 +00:00
parent 6e0e47098c
commit 46b3587585
1 changed files with 16 additions and 0 deletions

View File

@ -56,6 +56,19 @@ section_disclaimers() {
printf 'If you have a fix for said bug, please submit a pull request instead.\n' printf 'If you have a fix for said bug, please submit a pull request instead.\n'
} }
section_anatomy() {
title "Anatomy of an ANSI Escape Code"
printf 'Escape codes begin with `\e`, `\033`, or `\x1b`. These are all three different escape sequences which insert the ASCII character 27, or ESC. (This is why they''re called ANSI "escape" codes, because they begin with a literal escape character). The syntax `\e` is used throughout '
thebookofcolors
printf '. The choice is arbitrary, but consistent throughout.\n'
printf 'The next character is a `[`. This combination of characters, an escape followed by an open bracket, is called the "CSI", or "Control Sequence Introducer", which indicates the start of a control code.'
newline 2
printf 'Overall, a control sequence is formatted like so:\n'
printf '0x1B + "[" + <zero or more numbers, separated by semicolons> + <a letter>\n'
printf 'The CSI sequence we''ve gone over already. The easiest way to think about this is that the letter is the name of a function, and the semicolon-delimited numbers are the arguments to said function.\n'
printf 'By this model of thinking about escape sequences like function calls means you would read "\\e[0;1;34m" as m(0, 1, 34), and "\\e[A" as A().\n'
}
main() { main() {
thebookofcolors thebookofcolors
newline 2 newline 2
@ -64,6 +77,9 @@ main() {
newline newline
section_disclaimers section_disclaimers
newline
section_anatomy
#printf 'Use \\e (or \\033) followed by the control sequence specified next to activate that color.\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 'Use the reset sequence "[0m" to remove all set colors and styles.\n'