[[ANSI - General|ANSI]] generic control codes.
# Prefixes
These prefixes are often used for control codes and their abbreviations are often used in documentation without explaining what they are or how to use them.
| ABBR | Code | Origin | Name | Notes |
| ----- | ----- | ------ | --------------------------- | --------------------- |
| `ESC` | `\e` | | Escape | Prefix-Prefix |
| `DCS` | `\eP` | | Device Control String | Request term info |
| `CSI` | `\e[` | | Control Sequence Introducer | Colors, movement, etc |
| `OSC` | `\e]` | | Operating System Command | Terminated with `ST` |
# Suffixes
There are a variety of ways to end a control sequence. Some control codes are self-terminating and do not require a dedicate suffix, while others are finalized with a particular byte or range.
| ABBR | Code | Origin | Name | Notes |
| ----- | ------ | ------ | ----------------- | --------------------------------------------------------------------------------------------------------------- |
| `ST` | `\e\\` | | String Terminator | Actually the escape character followed by a single backslash (`\`), but most encodings require it to be doubled |
| `BEL` | `\007` | | Bell | Some terminals support using `BEL` in place of `ST`, but both typically work |
# Alternative Encodings for Escape
I typically use `\e` for `ESC` wherever available because it is shorter and easier to recognize, but some applications do not recognize this shortcut and other ways of encoding the escape sequence must be used. Annoyingly a lot of common POSIX utilities use different encodings.
| Code | Type | Usage |
| ------ | --------------- | ------------------------- |
| 27 | [[Decimal]] | |
| 033 | [[Octal]] | |
| 0x1B | [[Hexadecimal]] | |
| `\e` | Initial | [[POSIX Shell]], [[Ruby]] |
| `\033` | Octal | [[Awk]], [[Python]] |
| `\x1b` | Hex | [[sed]] |
# References
- https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf
- https://en.wikipedia.org/w/index.php?title=ANSI_escape_code
- https://handwiki.org/wiki/ANSI_escape_code