Terminal control sequences
A terminal takes one stream of bytes. Most of it is text to put on the screen, and the rest are control sequences: instructions to move the cursor, erase part of the screen, change colors, set the window title, and much else. This site documents a handful of them.
Each page states what a sequence does and then gives validation cases: a sequence of input and the screen it should leave behind. Those cases are not pictures. When you open a page your browser loads libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly, feeds every case into a real terminal, and shows what came out next to what was expected. You can step through a case one line of input at a time and watch the cursor move.
The tally in the last column is computed as this page loads, by running every case on every page. The notation page explains how cases are written.
C0 control characters
Single bytes from 00 to 1F that act on the terminal rather than being printed.
| BS | Backspace | BS |
… |
|---|---|---|---|
| BEL | Bell | BEL |
… |
| CAN | Cancel | CAN |
… |
| CR | Carriage Return | CR |
… |
| DC1 | Device Control One | DC1 |
… |
| ENQ | Enquiry | ENQ |
… |
| ESC | Escape | ESC |
… |
| FF | Form Feed | FF |
… |
| HT | Horizontal Tab | HT |
… |
| LF | Line Feed | LF |
… |
| NUL | Null | NUL |
… |
| SO | Shift Out | SO |
… |
| SUB | Substitute | SUB |
… |
| VT | Vertical Tab | VT |
… |
Escape sequences
ESC followed by one or more bytes: the oldest kind of multi-byte sequence.
| DECBI | Back Index | ESC 6 |
… |
|---|---|---|---|
| CSI | Control Sequence Introducer | CSI Pm Pi Pf |
… |
| DCS | Device Control String | DCS Pm Pi Pf Pt ST |
… |
| DECDLD | Down Line Load | DCS Pfn ; Pcn ; Pe ; Pcmw ; Pss ; Pu ; Pcmh ; Pcss { Dscs Sxbp1 ; … ; Sxbpn ST |
… |
| HTS | Horizontal Tabulation Set | ESC H |
… |
| DECKPAM | Keypad Application Mode | ESC = |
… |
| DECDWL | Double-Width Line | ESC # 6 |
… |
| LS2 | Locking Shift Two | ESC n |
… |
| NEL | Next Line | ESC E |
… |
| XTGETXRES | Request Resource Values | DCS + Q Pt ST |
… |
| DECRQSS | Request Selection or Setting | DCS $ q Pt ST |
… |
| XTGETTCAP | Request Termcap/Terminfo String | DCS + q Pt ST |
… |
| RIS | Reset to Initial State | ESC c |
… |
| RI | Reverse Index | ESC M |
… |
| DECSC | Save Cursor | ESC 7 |
… |
| DECALN | Screen Alignment Test | ESC # 8 |
… |
| XTSETTCAP | Set Termcap Data | DCS + p Pt ST |
… |
| SS2 | Single Shift Two | ESC N |
… |
| SPA | Start of Guarded Area | ESC V |
… |
| SOS | Start of String | ESC X Pt ST |
… |
| ST | String Terminator | ST |
… |
| DECUDK | User Defined Keys | DCS Pc ; Pl | Ky1/St1 ; … ; Kyn/Stn ST |
… |
| DECAUPSS | Assign User-Preference Supplemental Set | DCS Ps ! u Pt ST |
… |
Control sequences
CSI, then parameters, then a final byte: the bulk of what a terminal understands.
| DECCARA | Change Attributes in Rectangular Area | CSI Pt ; Pl ; Pb ; Pr ; Pm $ r |
… |
|---|---|---|---|
| HPA | Character Position Absolute | CSI Pn ` |
… |
| HPB | Character Position Backward | CSI Pn j |
… |
| HPR | Character Position Forward | CSI Pn a |
… |
| DECCRA | Copy Rectangular Area | CSI Pm $ v |
… |
| CUB | Cursor Backward | CSI Pn D |
… |
| CBT | Cursor Backward Tabulation | CSI Pn Z |
… |
| CHA | Cursor Character Absolute | CSI Pn G |
… |
| CUD | Cursor Down | CSI Pn B |
… |
| CUF | Cursor Forward | CSI Pn C |
… |
| CHT | Cursor Horizontal Tabulation | CSI Pn I |
… |
| CNL | Cursor Next Line | CSI Pn E |
… |
| CUP | Cursor Position | CSI Pl ; Pc H |
… |
| CPL | Cursor Preceding Line | CSI Pn F |
… |
| CTC | Cursor Tabulation Control | CSI Pm W |
… |
| CUU | Cursor Up | CSI Pn A |
… |
| DECDSR | DEC Device Status Reports | CSI ? Ps n |
… |
| DCH | Delete Character | CSI Pn P |
… |
| DL | Delete Line | CSI Pn M |
… |
| DA | Device Attributes | CSI Ps c |
… |
| DSR | Device Status Report | CSI Ps n |
… |
| ECH | Erase Character | CSI Pn X |
… |
| DECERA | Erase Rectangular Area | CSI Pt ; Pl ; Pb ; Pr $ z |
… |
| ED | Erase in Display | CSI Ps J |
… |
| EL | Erase in Line | CSI Ps K |
… |
| DECFRA | Fill Rectangular Area | CSI Pch ; Pt ; Pl ; Pb ; Pr $ x |
… |
| HVP | Horizontal and Vertical Position | CSI Pl ; Pc f |
… |
| ICH | Insert Character | CSI Pn @ |
… |
| IL | Insert Line | CSI Pn L |
… |
| DECIC | Insert Column | CSI Pn ' } |
… |
| DECTST | Invoke Confidence Test | CSI 4 ; Ps … y |
… |
| XTMODKEYS | Set Key Modifier Options | CSI > Pp ; Pv m |
… |
| CSI = u | Kitty Keyboard Protocol | CSI = Ps ; Pm u |
… |
| VPA | Line Position Absolute | CSI Pn d |
… |
| VPB | Line Position Backward | CSI Pn k |
… |
| VPR | Line Position Forward | CSI Pn e |
… |
| DECELR | Enable Locator Reports | CSI Ps ; Pu ' z |
… |
| MC | Media Copy | CSI Ps i |
… |
| NP | Next Page | CSI Pn U |
… |
| REP | Repeat | CSI Pn b |
… |
| XTVERSION | Report Version | CSI > Ps q |
… |
| DECRQCRA | Request Checksum of Rectangular Area | CSI Pi ; Pp ; Pt ; Pl ; Pb ; Pr * y |
… |
| DECRQM | Request Mode | CSI ? Pd $ p |
… |
| DECRQPSR | Request Presentation State Report | CSI Ps $ w |
… |
| SD | Scroll Down | CSI Pn T |
… |
| SL | Scroll Left | CSI Pn SP @ |
… |
| SU | Scroll Up | CSI Pn S |
… |
| DECSR | Secure Reset | CSI Pr + p |
… |
| DECSCL | Select Conformance Level | CSI Pl ; Pc " p |
… |
| SGR | Select Graphic Rendition | CSI Pm m |
… |
| SIMD | Select Implicit Movement Direction | CSI Ps ^ |
… |
| DECSNLS | Select Number of Lines per Screen | CSI Pn * | |
… |
| DECSCA | Select Character Protection Attribute | CSI Ps " q |
… |
| DECSCPP | Set Columns Per Page | CSI Pn $ | |
… |
| DECSCUSR | Set Cursor Style | CSI Ps SP q |
… |
| DECSLRM | Set Left and Right Margins | CSI Pl ; Pr s |
… |
| SM | Set Mode | CSI Pm h |
… |
| DECSTBM | Set Top and Bottom Margins | CSI Pt ; Pb r |
… |
| DECSTR | Soft Terminal Reset | CSI ! p |
… |
| DECSASD | Select Active Status Display | CSI Ps $ } |
… |
| TBC | Tabulation Clear | CSI Ps g |
… |
| DECRQTSR | Request Terminal State Report | CSI Ps $ u |
… |
| XTWINOPS | Window Operations | CSI Ps ; Ps ; Ps t |
… |
Private modes
Settings turned on with CSI ? Pm h and off with CSI ? Pm l, and asked about with DECRQM.
| ?1049 | Alternate Screen | CSI ? 1049 h |
… |
|---|---|---|---|
| DECARM | Autorepeat Mode | CSI ? 8 h |
… |
| DECAWM | Autowrap Mode | CSI ? 7 h |
… |
| ?2004 | Bracketed Paste | CSI ? 2004 h |
… |
| DECCOLM | Column Mode | CSI ? 3 h |
… |
| ?12 | Cursor Blink | CSI ? 12 h |
… |
| DECHCCM | Horizontal Cursor Coupling Mode | CSI ? 60 h |
… |
| DECCKM | Cursor Keys Mode | CSI ? 1 h |
… |
| ?1004 | Focus Events | CSI ? 1004 h |
… |
| DECKBUM | Keyboard Usage Mode | CSI ? 68 h |
… |
| ?1000 | Mouse Tracking | CSI ? 1000 h |
… |
| DECNRCM | National Replacement Character Set Mode | CSI ? 42 h |
… |
| DECOM | Origin Mode | CSI ? 6 h |
… |
| DECPEX | Print Extent Mode | CSI ? 19 h |
… |
| DECSCNM | Screen Mode | CSI ? 5 h |
… |
| DECSCLM | Scrolling Mode | CSI ? 4 h |
… |
| ?2026 | Synchronized Output | CSI ? 2026 h |
… |
| DECTCEM | Text Cursor Enable Mode | CSI ? 25 h |
… |
Operating system commands
Text-carrying commands for things outside the screen grid, such as the window title and the colors.
| OSC 4 | Change Color Palette | OSC 4 ; Pc ; Pt ST |
… |
|---|---|---|---|
| OSC 10 | Change Dynamic Colors | OSC 10 ; Pt ST |
… |
| OSC 52 | Manipulate Selection Data | OSC 52 ; Pc ; Pd ST |
… |
| OSC 3008 | Hierarchical Context Signalling | OSC 3008 ; start=id ; type=… ST |
… |
| OSC 8 | Hyperlink | OSC 8 ; Pp ; Pu ST |
… |
| OSC 21 | Kitty Color Protocol | OSC 21 ; key = value ; … ST |
… |
| OSC 99 | Kitty Extensions | OSC Ps ; metadata ; payload ST |
… |
| OSC 9 | Desktop Notification | OSC 9 ; Pt ST |
… |
| OSC 22 | Change Pointer Shape | OSC 22 ; Pt ST |
… |
| OSC 9 ; 4 | Progress Report | OSC 9 ; 4 ; Ps ; Pn ST |
… |
| OSC 2 | Set Window Title | OSC Ps ; Pt ST |
… |
| OSC 133 | Semantic Prompt | OSC 133 ; Ps ST |
… |
| OSC 7 | Report Working Directory | OSC 7 ; Pt ST |
… |
| OSC 1337 | iTerm2 Extensions | OSC 1337 ; Pt ST |
… |
Parsing
How a terminal reads sequences that are interrupted, malformed, or not quite what the standards describe.
| C0 in sequences | Controls Inside Sequences | CSI P… BS P… F |
… |
|---|---|---|---|
| Parameters | Parameters | CSI Pn ; Pn ; … F |
… |
| UTF-8 | UTF-8 and C1 Controls | C2 80 … C2 9F |
… |