Lokyr
Documentation

Escape codes

On this page

macOS · for program and plugin authors

Programs control the terminal by writing escape codes among their output: to move the cursor, color text, ask what the terminal supports, or report their progress. This page explains how the codes are written here, how a program finds out that it runs in Lokyr, and lists every code that Lokyr reads, with the version that brought it and its specification.

Try it

Run this command in Lokyr:

printf '\033[>q'; IFS= read -rs -t 1 -d '\' reply; reply=${reply#*|}; printf '%s\n' "${reply%$'\033'}"

It asks the terminal for its name and version, and prints Lokyr's answer. You should see Lokyr's version, such as:

lokyr 1.2.0

How the codes are written

The pages of this reference write each code the way xterm's control sequences do, with spaces between its parts to make it easier to read. A program sends it without the spaces.

NameBytesIn printf
ESCthe escape character, 0x1B\033
CSIESC [\033[
OSCESC ]\033]
DCSESC P\033P
APCESC _\033_
ST, the string terminatorESC \\033\\
BEL0x07, which ends an OSC too\a

Ps stands for one number, Pm for several separated by ;, and Pt for text. An OSC that ends with BEL gets its answer ended with BEL, and one that ends with ST gets ST.

Find out that a program runs in Lokyr

Lokyr sets these variables for the programs of its panes:

VariableValue
TERM_PROGRAMlokyr
TERM_PROGRAM_VERSIONLokyr's version, such as 1.2.0
TERMxterm-256color by default, as [terminal] term sets it
COLORTERMtruecolor
LOKYR_RESOURCES_DIRThe folder of Lokyr's resources, such as its shell integration scripts

The variables don't cross ssh, and a program started under tmux or sudo may not see them. To learn what the terminal supports wherever the program runs, ask the terminal itself: it answers these queries with these exact replies.

QueryAsksLokyr replies
CSI > qXTVERSION, the terminal's name and versionDCS > | lokyr 1.2.0 ST
CSI cDA1, the primary attributesCSI ? 62 ; 22 c: a VT220 with ANSI colors
CSI > cDA2, the secondary attributesCSI > 1 ; 10 ; 0 c
CSI = cDA3, the unit's identityDCS ! | 00000000 ST
CSI ? Ps $ pDECRQM, whether a mode is setCSI ? Ps ; Pm $ y: 1 set, 2 reset, 3 always set, 4 always reset, 0 unknown
CSI ? uThe keyboard's reporting flagsCSI ? Ps u, the flags in force
CSI ? 996 nThe color schemeCSI ? 997 ; 1 n for a dark theme, CSI ? 997 ; 2 n for a light one
OSC 11 ; ? STThe background color, and 10 the text's, 12 the cursor'sOSC 11 ; rgb:rrrr/gggg/bbbb ST
DCS + q Pt STXTGETTCAP, a terminfo capability, its name in hexadecimalDCS 1 + r Pt = Pt ST, the name and its value in hexadecimal; DCS 1 + r Pt ST for a capability that is true or false; DCS 0 + r Pt ST for a name that Lokyr doesn't know

Prefer a query for each feature, such as DECRQM for a mode, to a check of the name or the version: a feature's query keeps working as Lokyr and other terminals change.

The codes that Lokyr reads

xterm's control sequences describe the standard codes, which Lokyr reads as xterm does unless the table says otherwise. The codes of a page of their own link to it: progress and status and notifications. The codes that a later version brought say so in the Since column. Lokyr ignores a code that it doesn't read, and shows nothing of it.

Controls, the cursor and editing

FamilyCodesSince
C0 controlsBEL, BS, HT, LF, VT, FF, CR, SO, SI0.2
ESCDECSC and DECRC (ESC 7 and 8), IND, NEL, HTS, RI, DECBI and DECFI (ESC 6 and 9), RIS, DECKPAM and DECKPNM, the G0 to G3 character sets, LS2 and LS3, SS2 and SS3, DECALN0.2
The cursorCUU, CUD, CUF, CUB, CNL, CPL, CHA, CUP, HVP, VPA, VPR, HPA, HPR, CHT, CBT, DECSCUSR (the cursor's shape)0.2
EditingICH, DCH, IL, DL, ECH, ED, EL, DECSED, DECSEL, REP, SU, SD, DECSTBM, DECSLRM, SCOSC and SCORC, DECSCA, SPA and EPA (ESC V and W), TBC; DECIC and DECDC; the rectangles, DECCRA, DECERA, DECFRA, DECSERA0.2
Resets and levelsRIS, DECSTR (soft reset), DECSCL (the conformance level, which DECRQSS reports)0.2

Text attributes and modes

FamilyCodesSince
SGR, the text's attributes0 to 9, 21 to 29, 30 to 37, 90 to 97, 38;5 and 38;2 (also with :), 39, 40 to 47, 100 to 107, 48, 49, 4:0 to 4:5 (the underline's styles), 53 and 55 (overline), 58 and 59 (the underline's color)0.2
ANSI modesIRM (4), LNM (20); GATM, SRTM, VEM, HEM, PUM, FEAM, FETM, MATM, TTM, SATM, TSM and EBM reported as always reset0.2
DEC modes1 (DECCKM), 3 (DECCOLM), 4 (DECSCLM), 5 (DECSCNM), 6 (DECOM), 7 (DECAWM), 12 (the cursor's blink), 25 (DECTCEM), 40 (DECCOLM allowed), 41, 45 (reverse wrap), 1045 (extended reverse wrap), 47, 1047 and 1049 (the alternate screen), 1048, 66 (DECNKM), 67 (DECBKM), 69 (DECLRMM), 95 (DECNCSM), 9, 1000, 1002, 1003, 1006 and 1016 (the mouse), 1004 (focus), 1007 (alternate scroll), 1036 (Meta sends ESC), 2004 (bracketed paste)0.2
Synchronized outputMode 2026, its specification0.2
Grapheme clustersMode 2027, its specification0.2
The color scheme's reportsMode 2031 and CSI ? 996 n, their specification0.7

Reports

FamilyCodesSince
Identity and stateDA1, DA2, DA3, DECID, DSR (5n and 6n), DECDSR (?6n, ?15n, ?25n, ?26n, ?53n, ?55n, ?56n, ?62n, ?63n, ?75n, ?85n), DECRQM, DECRQSS, XTVERSION, XTGETTCAP0.2
XTWINOPS14t, 16t and 18t (the sizes), 22t and 23t (the title's stack); the title modes (CSI > Ps t and T); XTSAVE and XTRESTORE (CSI ? Pm s and r). A program can't move, resize or minimize the window, nor read its title (21t) or a rectangle's checksum (DECRQCRA)0.2

OSC

CodeWhat it doesSinceSpecification
OSC 0, 1 and 2The window's and the tab's title0.2xterm
OSC 4 and 104The palette's colors, set, asked for and reset0.2xterm
OSC 5 and 105The special colors0.2xterm
OSC 7The shell's folder, as a file URL, which new tabs and splits start in0.2Shell integration
OSC 8Hyperlinks0.2Hyperlinks in terminals
OSC 10, 11 and 12, and 110, 111 and 112The text's, the background's and the cursor's colors, set, asked for and reset0.2xterm
OSC 52The clipboard: written, and read only as [clipboard] read allows0.2xterm
OSC 9 and 777Desktop notifications0.2OSC 9
OSC 6 ; 1The tab's color0.5.1Its escape codes
OSC 9 ; 4A program's progress, on its tab0.5.1Progress bar sequences
OSC 133Semantic prompts: where each prompt, command and output starts0.7Semantic prompts, and Shell integration
OSC 133 cl=, click_events= and P;k=rA click in the command line, and a right prompt's mark1.3Semantic prompts, and Shell integration
OSC 133 lokyr_spaced, lokyr_started= and lokyr_ended=Lokyr's own options, which a pane's restored scrollback holds: the blank row before a prompt that is there already, and a command's start and end times, in milliseconds since the Unix epoch1.5Semantic prompts
OSC 1337 File=Inline images, whole or in parts (MultipartFile=, FilePart=, FileEnd)1.0Inline images
OSC 99Desktop notifications with a title and a body, in parts, and the query of what the terminal supports1.3Desktop notifications
OSC 7501A program's status, such as working, waiting or done1.3Program Status Protocol
OSC 21337A session's status, shown on its tab1.3Session status

The keyboard and graphics

FamilyCodesSinceSpecification
The keyboard protocol that reports every keyCSI > Ps u, CSI < Ps u, CSI = Ps ; Ps u and CSI ? u0.2Keyboard protocol
XTMODKEYS, the keys of modifyOtherKeysCSI > 4 ; Pv m, its reset CSI > 4 n, and its query CSI ? 4 m, which Lokyr answers CSI > 4 ; Pv m0.2xterm
GraphicsAPC G, images sent directly1.0Graphics protocol

See also