^[control-codes
live in libghostty-vt

Terminal control sequences

View as Markdown

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.

BEL Bell BEL …
BS Backspace BS …
CAN Cancel CAN …
CR Carriage Return CR …
DC1 Device Control One DC1 …
DC3 Device Control Three
ENQ Enquiry ENQ …
ESC Escape ESC …
FF Form Feed FF …
HT Horizontal Tab HT …
LF Line Feed LF …
NUL Null NUL …
SI Shift In
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.

APC Application Program Command
CSI Control Sequence Introducer CSI Pm Pi Pf …
DCS Device Control String DCS Pm Pi Pf Pt ST …
DECALN Screen Alignment Test ESC # 8 …
DECBI Back Index ESC 6 …
DECDHLB Double-Height Line, Bottom Half
DECDHLT Double-Height Line, Top Half
DECDWL Double-Width Line ESC # 6 …
DECFI Forward Index
DECKPAM Keypad Application Mode ESC = …
DECKPNM Keypad Numeric Mode
DECRC Restore Cursor
DECSC Save Cursor ESC 7 …
DECSWL Single-Width Line
EPA End of Guarded Area
HTS Horizontal Tabulation Set ESC H …
LS2 Locking Shift Two ESC n …
LS3 Locking Shift Three
NEL Next Line ESC E …
PM Privacy Message
RI Reverse Index ESC M …
RIS Reset to Initial State ESC c …
SOS Start of String ESC X Pt ST …
SPA Start of Guarded Area ESC V …
SS2 Single Shift Two ESC N …
SS3 Single Shift Three
ST String Terminator ST …

Control sequences

CSI, then parameters, then a final byte: the bulk of what a terminal understands.

CBT Cursor Backward Tabulation CSI Pn Z …
CHA Cursor Character Absolute CSI Pn G …
CHT Cursor Horizontal Tabulation CSI Pn I …
CNL Cursor Next Line CSI Pn E …
CPL Cursor Preceding Line CSI Pn F …
CPR Active Position Report
CSI u Kitty Keyboard Protocol CSI = Ps ; Pm u …
CTC Cursor Tabulation Control CSI Pm W …
CUB Cursor Backward CSI Pn D …
CUD Cursor Down CSI Pn B …
CUF Cursor Forward CSI Pn C …
CUP Cursor Position CSI Pl ; Pc H …
CUU Cursor Up CSI Pn A …
DA Device Attributes CSI Ps c …
DCH Delete Character CSI Pn P …
DECCARA Change Attributes in Rectangular Area CSI Pt ; Pl ; Pb ; Pr ; Pm $ r …
DECCIR Cursor Information Report
DECCKSR Memory Checksum Report
DECCRA Copy Rectangular Area CSI Pm $ v …
DECDC Delete Column
DECDSR DEC Device Status Reports CSI ? Ps n …
DECEFR Enable Filter Rectangle
DECELR Enable Locator Reports CSI Ps ; Pu ' z …
DECERA Erase Rectangular Area CSI Pt ; Pl ; Pb ; Pr $ z …
DECFRA Fill Rectangular Area CSI Pch ; Pt ; Pl ; Pb ; Pr $ x …
DECIC Insert Column CSI Pn ' } …
DECID Identify Terminal
DECLKD Locator Key Definition
DECMSR Macro Space Report
DECRARA Reverse Attributes Rectangular Area
DECRPM Report Mode
DECRQCRA Request Checksum of Rectangular Area CSI Pi ; Pp ; Pt ; Pl ; Pb ; Pr * y …
DECRQLP Request Locator Position
DECRQM Request Mode CSI ? Pd $ p …
DECRQPSR Request Presentation State Report CSI Ps $ w …
DECRQTSR Request Terminal State Report CSI Ps $ u …
DECRST DEC Private Mode Reset CSI ? Pm l …
DECRSTS Restore Terminal State
DECSACE Select Attribute Change Extent
DECSASD Select Active Status Display CSI Ps $ } …
DECSCA Select Character Protection Attribute CSI Ps " q …
DECSCL Select Conformance Level CSI Pl ; Pc " p …
DECSCPP Set Columns Per Page CSI Pn $ | …
DECSCUSR Set Cursor Style CSI Ps SP q …
DECSED Selective Erase in Display
DECSEL Selective Erase in Line
DECSERA Selective Erase Rectangular Area
DECSET DEC Private Mode Set CSI ? Pm h …
DECSLE Select Locator Events
DECSLRM Set Left and Right Margins CSI Pl ; Pr s …
DECSNLS Select Number of Lines per Screen CSI Pn * | …
DECSR Secure Reset CSI Pr + p …
DECSRC Secure Reset Confirmation
DECSSDT Select Status Display Type
DECST8C Set Tab at Every 8 Columns
DECSTBM Set Top and Bottom Margins CSI Pt ; Pb r …
DECSTR Soft Terminal Reset CSI ! p …
DECTABSR Tabulation Stop Report
DECTSR Terminal State Report
DECTST Invoke Confidence Test CSI 4 ; Ps … y …
DECXCPR Extended Cursor Position Report
DL Delete Line CSI Pn M …
DSR Device Status Report CSI Ps n …
ECH Erase Character CSI Pn X …
ED Erase in Display CSI Ps J …
EL Erase in Line CSI Ps K …
HPA Character Position Absolute CSI Pn ` …
HPB Character Position Backward CSI Pn j …
HPR Character Position Forward CSI Pn a …
HVP Horizontal and Vertical Position CSI Pl ; Pc f …
ICH Insert Character CSI Pn @ …
IL Insert Line CSI Pn L …
MC Media Copy CSI Ps i …
NP Next Page CSI Pn U …
PP Preceding Page
PPA Page Position Absolute
PPB Page Position Backward
PPR Page Position Forward
REP Repeat CSI Pn b …
RM Reset Mode CSI Pm l …
SD Scroll Down CSI Pn T …
SGR Select Graphic Rendition CSI Pm m …
SIMD Select Implicit Movement Direction CSI Ps ^ …
SL Scroll Left CSI Pn SP @ …
SM Set Mode CSI Pm h …
SR Scroll Right
SU Scroll Up CSI Pn S …
TBC Tabulation Clear CSI Ps g …
VPA Line Position Absolute CSI Pn d …
VPB Line Position Backward CSI Pn k …
VPR Line Position Forward CSI Pn e …
XTCHECKSUM Select Checksum Extension
XTMODKEYS Set Key Modifier Options CSI > Pp ; Pv m …
XTQMODKEYS Query Key Modifier Options
XTRESTORE Restore DEC Private Mode Values CSI ? Pm r …
XTSAVE Save DEC Private Mode Values CSI ? Pm s …
XTVERSION Report Version CSI > Ps q …
XTWINOPS Window Operations CSI Ps ; Ps ; Ps t …

ANSI modes

The modes ECMA-48 numbers, turned on with CSI Pm h and off with CSI Pm l, and asked about with DECRQM.

1 GATMGuarded Area Transfer Mode CSI 1 h/l …
2 KAMKeyboard Action Mode CSI 2 h/l …
3 CRMControl Representation Mode CSI 3 h/l …
4 IRMInsertion Replacement Mode CSI 4 h/l …
5 SRTMStatus Report Transfer Mode CSI 5 h/l …
6 ERMErasure Mode CSI 6 h/l …
7 VEMLine Editing Mode CSI 7 h/l …
8 BDSMBi-directional Support Mode CSI 8 h/l …
9 DCSMDevice Component Select Mode CSI 9 h/l …
10 HEMCharacter Editing Mode CSI 10 h/l …
11 PUMPositioning Unit Mode CSI 11 h/l …
12 SRMSend/Receive Mode CSI 12 h/l …
13 FEAMFormat Effector Action Mode CSI 13 h/l …
14 FETMFormat Effector Transfer Mode CSI 14 h/l …
15 MATMMultiple Area Transfer Mode CSI 15 h/l …
16 TTMTransfer Termination Mode CSI 16 h/l …
17 SATMSelected Area Transfer Mode CSI 17 h/l …
18 TSMTabulation Stop Mode CSI 18 h/l …
19 EBMEditing Boundary Mode CSI 19 h/l …
20 LNMLine Feed/New Line Mode CSI 20 h/l …
21 GRCMGraphic Rendition Combination Mode CSI 21 h/l …
22 ZDMZero Default Mode CSI 22 h/l …

Private modes

Settings turned on with CSI ? Pm h and off with CSI ? Pm l, and asked about with DECRQM.

?1 DECCKMCursor Keys Mode CSI ? 1 h/l …
?3 DECCOLMColumn Mode CSI ? 3 h/l …
?4 DECSCLMScrolling Mode CSI ? 4 h/l …
?5 DECSCNMScreen Mode CSI ? 5 h/l …
?6 DECOMOrigin Mode CSI ? 6 h/l …
?7 DECAWMAutowrap Mode CSI ? 7 h/l …
?8 DECARMAutorepeat Mode CSI ? 8 h/l …
?9 X10 Mouse
?12 Cursor Blink CSI ? 12 h/l …
?18 DECPFF Print Form Feed Mode
?19 DECPEXPrint Extent Mode CSI ? 19 h/l …
?25 DECTCEMText Cursor Enable Mode CSI ? 25 h/l …
?40 Allow 80/132 Column Mode
?42 DECNRCMNational Replacement Character Set Mode CSI ? 42 h/l …
?46 XTLOGGINGStart Logging or DECGPBMGraphics Print Background Mode CSI ? 46 h/l …
?47 Alternate Screen
?60 DECHCCMHorizontal Cursor Coupling Mode CSI ? 60 h/l …
?61 DECVCCM Vertical Cursor Coupling Mode
?64 DECPCCM Page Cursor Coupling Mode
?68 DECKBUMKeyboard Usage Mode CSI ? 68 h/l …
?80 DECSDMSixel Display Mode CSI ? 80 h/l …
?95 DECNCSMNo Clearing Screen On Column Change CSI ? 95 h/l …
?1000 Mouse Tracking CSI ? 1000 h/l …
?1001 Highlight Mouse Tracking
?1002 Button-Event Mouse Tracking
?1003 Any-Event Mouse Tracking
?1004 Focus Events CSI ? 1004 h/l …
?1005 UTF-8 Mouse Encoding
?1006 SGR Mouse Encoding
?1007 Alternate Scroll
?1015 urxvt Mouse Encoding
?1016 SGR Pixel Mouse Encoding
?1046 Allow Alternate Screen
?1047 Alternate Screen, Cleared on Leaving
?1048 Save Cursor
?1049 Alternate Screen CSI ? 1049 h/l …
?2004 Bracketed Paste CSI ? 2004 h/l …
?2026 Synchronized Output CSI ? 2026 h/l …

Device control strings

Functions sent as a string between DCS and ST: status requests, key definitions, fonts, and xterm's queries.

DECAUPSS Assign User-Preference Supplemental Set DCS Ps ! u Pt ST …
DECDLD Down Line Load DCS Pfn ; Pcn ; Pe ; Pcmw ; Pss ; Pu ; Pcmh ; Pcss { Dscs Sxbp1 ; … ; Sxbpn ST …
DECRPSS Report Selection or Setting
DECRQSS Request Selection or Setting DCS $ q Pt ST …
DECRQUPSS Request User-Preference Supplemental Set
DECUDK User Defined Keys DCS Pc ; Pl | Ky1/St1 ; … ; Kyn/Stn ST …
ReGIS Remote Graphic Instruction Set DCS Pm p commands ST …
Sixel Sixel Graphics DCS P1 ; P2 ; P3 q s…s ST …
XTGETTCAP Request Termcap/Terminfo String DCS + q Pt ST …
XTGETXRES Request Resource Values DCS + Q Pt ST …
XTSETTCAP Set Termcap Data DCS + p Pt ST …

Operating system commands

Text-carrying commands for things outside the screen grid, such as the window title and the colors.

OSC 0 Set Icon Name and Window Title OSC 0 ; Pt ST …
OSC 1 Set Icon Name OSC 1 ; Pt ST …
OSC 2 Set Window Title OSC 2 ; Pt ST …
OSC 3 Set X Property OSC 3 ; prop = value ST …
OSC 4 Change Color Palette OSC 4 ; Pc ; Pt ST …
OSC 5 Change Special Color OSC 5 ; Pc ; Pt ST …
OSC 6 Enable Special Color OSC 6 ; Pc ; Pf ST …
OSC 7 Report Working Directory OSC 7 ; Pt ST …
OSC 8 Hyperlink OSC 8 ; Pp ; Pu ST …
OSC 9 Desktop Notification OSC 9 ; Pt ST …
OSC 9 ; 1 Sleep OSC 9 ; 1 ; ms ST …
OSC 9 ; 2 Message Box OSC 9 ; 2 ; text ST …
OSC 9 ; 3 Tab Title OSC 9 ; 3 ; text ST …
OSC 9 ; 4 Progress Report OSC 9 ; 4 ; Ps ; Pn ST …
OSC 9 ; 5 Wait for a Key OSC 9 ; 5 ST …
OSC 9 ; 6 Run a Macro OSC 9 ; 6 ; macro ST …
OSC 9 ; 7 Run a Process OSC 9 ; 7 ; cmd ST …
OSC 9 ; 8 Environment Variable OSC 9 ; 8 ; env ST …
OSC 9 ; 9 Working Directory OSC 9 ; 9 ; dir ST …
OSC 9 ; 10 xterm Emulation OSC 9 ; 10 ; n ST …
OSC 9 ; 11 Comment OSC 9 ; 11 ; text ST …
OSC 9 ; 12 Prompt Start OSC 9 ; 12 ST …
OSC 10 Text Foreground Color OSC 10 ; Pt ST …
OSC 11 Text Background Color OSC 11 ; Pt ST …
OSC 12 Text Cursor Color OSC 12 ; Pt ST …
OSC 13 Pointer Foreground Color OSC 13 ; Pt ST …
OSC 14 Pointer Background Color OSC 14 ; Pt ST …
OSC 15 Tektronix Foreground Color OSC 15 ; Pt ST …
OSC 16 Tektronix Background Color OSC 16 ; Pt ST …
OSC 17 Highlight Background Color OSC 17 ; Pt ST …
OSC 18 Tektronix Cursor Color OSC 18 ; Pt ST …
OSC 19 Highlight Foreground Color OSC 19 ; Pt ST …
OSC 21 Kitty Colors, or DECSWT OSC 21 ; key = value ; … ST …
OSC 22 Change Pointer Shape OSC 22 ; Pt ST …
OSC 30 Tab Title (Konsole) OSC 30 ; Pt ST …
OSC 31 Working Directory (old Konsole) OSC 31 ; Pt ST …
OSC 32 Tab Icon (Konsole) OSC 32 ; Pt ST …
OSC 34 Tab Color (Konsole) OSC 34 ; Pt ST …
OSC 46 Change Log File OSC 46 ; Pt ST …
OSC 50 Set Font OSC 50 ; Pt ST …
OSC 51 Reserved for Emacs OSC 51 ; Pt ST …
OSC 52 Manipulate Selection Data OSC 52 ; Pc ; Pd ST …
OSC 60 Query Allowed Features OSC 60 ST …
OSC 61 Query Disallowed Features OSC 61 ; Pt ST …
OSC 62 Query Allowable Features OSC 62 ; Pt ST …
OSC 66 Text Sizing OSC 66 ; metadata ; text ST …
OSC 72 Drag and Drop OSC 72 ; metadata ; payload ST …
OSC 99 Desktop Notifications OSC 99 ; metadata ; payload ST …
OSC 104 Reset Color Palette OSC 104 ; Pc ST …
OSC 105 Reset Special Color OSC 105 ; Pc ST …
OSC 106 Special Color Modes OSC 106 ; Pc ; Pf ST …
OSC 110 Reset Text Foreground Color OSC 110 ST …
OSC 111 Reset Text Background Color OSC 111 ST …
OSC 112 Reset Text Cursor Color OSC 112 ST …
OSC 113 Reset Pointer Foreground Color OSC 113 ST …
OSC 114 Reset Pointer Background Color OSC 114 ST …
OSC 115 Reset Tektronix Foreground Color OSC 115 ST …
OSC 116 Reset Tektronix Background Color OSC 116 ST …
OSC 117 Reset Highlight Background Color OSC 117 ST …
OSC 118 Reset Tektronix Cursor Color OSC 118 ST …
OSC 119 Reset Highlight Foreground Color OSC 119 ST …
OSC 133 Semantic Prompt OSC 133 ; Ps ST …
OSC 176 Set App ID OSC 176 ; Pt ST …
OSC 440 Play Sound OSC 440 ; Pt ST …
OSC 555 Flash Screen OSC 555 ST …
OSC 633 VS Code Shell Integration OSC 633 ; Ps [ ; Pt ] ST …
OSC 666 Set Terminal Property OSC 666 ; Pt ST …
OSC 701 Set Locale OSC 701 ; Pt ST …
OSC 702 Report Version OSC 702 ; ? ST …
OSC 710 Set Normal Font OSC 710 ; Pt ST …
OSC 711 Set Bold Font
OSC 712 Set Italic Font
OSC 713 Set Bold Italic Font
OSC 720 Scroll View Up OSC 720 ; Pn ST …
OSC 721 Scroll View Down
OSC 776 Report Cell Size OSC 776 ; ? ST …
OSC 777 Perl Extension Command OSC 777 ; prefix ; Pt ST …
OSC 1337 iTerm2 Extensions OSC 1337 ; Pt ST …
OSC 3008 Hierarchical Context Signalling OSC 3008 ; start=id ; type=… ST …
OSC 5522 Clipboard by MIME Type OSC 5522 ; metadata ; payload ST …
OSC 7770 Set Font Size OSC 7770 ; Pt ST …
OSC 7777 Set Font and Window Size OSC 7777 ; Pt ST …
OSC 9999 Agent Status OSC 9999 ; JSON ST …
OSC 21337 Session Status OSC 21337 ; key=value ; … ST …
OSC 30001 Push Colors OSC 30001 ST …
OSC 30101 Pop Colors OSC 30101 ST …
OSC I Set Icon (dtterm) OSC I Pt ST …
OSC L Set Icon Name (dtterm) OSC L Pt ST …
OSC P Set Palette (Linux) OSC P n rrggbb ST …
OSC R Reset Palette (Linux) OSC R ST …
OSC l Set Window Title (dtterm) OSC l 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 …

Proposals

Control sequences that have been proposed but are not yet in any standard, summarized as their authors wrote them.

APC 25a1 Glyph Protocol APC 25a1 ; verb ; key=value … ; payload ST …
OSC 88 Terminal Resume Protocol OSC 88 ; op ; key=value … ST …
OSC 7501 Program Status Protocol OSC 7501 ; key=value : key=value … ST …
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.