diff --git a/README.md b/README.md index d225565..5598b09 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ A collection of pure POSIX `sh` alternatives to external processes * [FILE PATHS](#file-paths) * [Get the directory name of a file path](#get-the-directory-name-of-a-file-path) * [Get the base-name of a file path](#get-the-base-name-of-a-file-path) +* [ESCAPE SEQUENCES](#escape-sequences) + * [Text Colors](#text-colors) + * [Text Attributes](#text-attributes) + * [Cursor Movement](#cursor-movement) + * [Erasing Text](#erasing-text) @@ -297,3 +302,59 @@ $ basename ~/Pictures/Wallpapers/1.jpg $ basename ~/Pictures/Downloads/ Downloads ``` + +# ESCAPE SEQUENCES + +Contrary to popular belief, there is no issue in utilizing raw escape sequences. Using `tput` abstracts the same ANSI sequences as if printed manually. Worse still, `tput` is not actually portable. There are a number of `tput` variants each with different commands and syntaxes (*try `tput setaf 3` on a FreeBSD system*). Raw sequences are fine. + +## Text Colors + +**NOTE:** Sequences requiring RGB values only work in True-Color Terminal Emulators. + +| Sequence | What does it do? | Value | +| -------- | ---------------- | ----- | +| `\e[38;5;m` | Set text foreground color. | `0-255` +| `\e[48;5;m` | Set text background color. | `0-255` +| `\e[38;2;;;m` | Set text foreground color to RGB color. | `R`, `G`, `B` +| `\e[48;2;;;m` | Set text background color to RGB color. | `R`, `G`, `B` + +## Text Attributes + +| Sequence | What does it do? | +| -------- | ---------------- | +| `\e[m` | Reset text formatting and colors. +| `\e[1m` | Bold text. | +| `\e[2m` | Faint text. | +| `\e[3m` | Italic text. | +| `\e[4m` | Underline text. | +| `\e[5m` | Slow blink. | +| `\e[7m` | Swap foreground and background colors. | + + +## Cursor Movement + +| Sequence | What does it do? | Value | +| -------- | ---------------- | ----- | +| `\e[;H` | Move cursor to absolute position. | `line`, `column` +| `\e[H` | Move cursor to home position (`0,0`). | +| `\e[A` | Move cursor up N lines. | `num` +| `\e[B` | Move cursor down N lines. | `num` +| `\e[C` | Move cursor right N columns. | `num` +| `\e[D` | Move cursor left N columns. | `num` +| `\e[s` | Save cursor position. | +| `\e[u` | Restore cursor position. | + + +## Erasing Text + +| Sequence | What does it do? | +| -------- | ---------------- | +| `\e[K` | Erase from cursor position to end of line. +| `\e[1K` | Erase from cursor position to start of line. +| `\e[2K` | Erase the entire current line. +| `\e[J` | Erase from the current line to the bottom of the screen. +| `\e[1J` | Erase from the current line to the top of the screen. +| `\e[2J` | Clear the screen. +| `\e[2J\e[H` | Clear the screen and move cursor to `0,0`. + +