Add Anatomy of an ANSI Escape Code section
This commit is contained in:
parent
6e0e47098c
commit
46b3587585
|
@ -56,6 +56,19 @@ section_disclaimers() {
|
|||
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() {
|
||||
thebookofcolors
|
||||
newline 2
|
||||
|
@ -64,6 +77,9 @@ main() {
|
|||
newline
|
||||
|
||||
section_disclaimers
|
||||
newline
|
||||
|
||||
section_anatomy
|
||||
|
||||
#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'
|
||||
|
|
Loading…
Reference in New Issue