Reference Overview
The pages you will keep open in a second tab while you work.
| Page | Use it for |
|---|---|
| Glossary | Every term, defined precisely, with the loose usage named as loose |
| Escape Sequence Cheat Sheet | Every sequence you implement, with a shell command that generates it |
| termios Cheat Sheet | Every flag, every control character, the stty equivalents |
| Key Encoding Table | The specification for terminal-input — one row per unit test |
| Primary Sources | The actual standards, which to read, and which to ignore |
| The Terminal Ecosystem | What every real terminal and multiplexer is, and what to steal from each |
The Five-Minute Diagnostic
Bookmark this block. It resolves most terminal confusion.
# WHAT am I connected to?
tty; echo $TERM; stty size
ps -o pid,ppid,pgid,sid,tpgid,stat,tty,comm -p $$
# WHAT is the line discipline doing?
stty -a
stty -a -F /dev/pts/N # Linux, another terminal
stty -a -f /dev/ttysNNN # macOS
# WHAT bytes is my keyboard sending?
cat -v
stty raw -echo; head -c 20 | xxd; stty sane
# WHAT bytes is that program emitting?
script -q -c 'the-program' /dev/null | cat -v | head -40
# WHERE is the cursor, really?
printf '\033[6n'; read -r -d R p; echo; echo "${p#*[}"
# MY TERMINAL IS BROKEN
stty sane # input broken (press Ctrl+J if Enter does nothing)
printf '\033c' # display broken — RIS, hard reset
reset # both
# turn off everything a crashed TUI may have left on:
printf '\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l\033[?1004l\033[?25h\033[?1049l\033[0m'
Which Page Answers Which Question
| Question | Page |
|---|---|
"What does CSI 1;5 A mean?" | Escape sequences |
| "What byte does Ctrl+Alt+Shift+F5 send?" | Key encoding |
"Which flag makes ^C a signal?" | termios |
| "What exactly is a controlling terminal?" | Glossary |
| "Where is this behavior actually specified?" | Primary sources |
| "How does Ghostty differ from Alacritty?" | Ecosystem |
"Why is Enter 0x0D?" | The Hitchhiker's Guide |
The Numbers Worth Memorizing
| Value | Meaning |
|---|---|
0x07 | BEL — bell, and an OSC terminator |
0x08 | BS — cursor left; does not erase |
0x09 | HT — tab |
0x0A | LF — down a line, not to column 0 |
0x0D | CR — column 0. The Enter key sends this. |
0x1B | ESC — the escape introducer, and Ctrl+[ |
0x7F | DEL — the Backspace key sends this |
0x1B 0x5B | CSI — Control Sequence Introducer |
0x1B 0x4F | SS3 — application-mode cursor keys and F1–F4 |
0x1B 0x5D | OSC — Operating System Command |
0x1B 0x5C | ST — String Terminator |
?1049 | Alternate screen + save cursor + clear |
?1 | DECCKM — application cursor keys |
?7 | DECAWM — autowrap (default on) |
?25 | DECTCEM — cursor visible (default on) |
?2004 | Bracketed paste |
?1006 | SGR mouse encoding |
The Ctrl rule: Ctrl + char = uppercase(char) & 0x1F.
The modifier parameter: 1 + shift(1) + alt(2) + ctrl(4) + super(8).
The 256-palette cube: 16 + 36r + 6g + b, levels [0, 95, 135, 175, 215, 255].
Start with the Glossary, or jump to whichever page answers the question in front of you.