^[control-codes
live in libghostty-vt

Control sequences

DA Device Attributes

View as Markdown

Ask the terminal what kind of terminal it is.

CSI Ps c

DECID Identify Terminal

ESC Z
Defaults
Ps = 0
ECMA-48
§8.3.24 DA – Device Attributes, p. 37
DEC STD 070
§4, ch. 5 Device Attributes (Primary), p. 17
VT220
§4.17.1 Device Attributes (DA)
VT510
DA1—Primary Device Attributes

With Ps left out or 0, DA asks the terminal to identify itself, and the terminal answers CSI ? Ps ; … c. DEC STD 070 defines what the answer means. The first parameter is the kind of device and the level of DEC’s architecture it conforms to: 61 to 69 are character-cell displays, so 62 is one conforming to level 2. The rest name extensions it has, such as 22 for ANSI color.

With any other Ps, ECMA-48 says DA does the opposite: it identifies the sender, with Ps as a device type code. A terminal receiving one has not been asked anything. DEC STD 070 likewise makes only an omitted or zero parameter a request, and xterm answers only those.

What the terminal says about itself is the host program’s choice. libghostty-vt asks its host and encodes whatever comes back, and the cases here run with a default xterm’s answers, as the rest of the cases follow one. xterm is a VT420 by default, so it answers level 4, CSI ? 64 ; 1 ; 2 ; 6 ; 9 ; 15 ; 17 ; 18 ; 21 ; 22 ; 28 c: 132 columns, a printer, selective erase, national character sets, technical characters, terminal state interrogation, user windows, horizontal scrolling, ANSI color and rectangular editing. Its secondary answer, CSI > 41 ; 412 ; 0 c, names a VT420 and its own patch number. Ghostty itself answers as a VT220, level 2 with ANSI color. See the notation page.

Two DEC extensions ask for more:

  • CSI > c is secondary DA, the VT510 manual’s DA2. The answer CSI > Pp ; Pv ; Pc c gives the terminal type, the firmware version and the ROM cartridge.
  • CSI = c is tertiary DA, DA3. The answer is a control string, DCS ! | D…D ST, holding the terminal’s unit ID as four hexadecimal pairs.

DECID, ESC Z, is the VT52-era way of asking the same thing as DA. The VT510 manual says it makes the terminal send its DA answer, and that programs should use DA instead.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Partlyprimary and secondary DA and DECID (§4.17.1 Device Attributes (DA)); no tertiary DA
VT510manual, 1st ed., 1993YesDA1, DA2, DA3
xtermpatch 412, xterm-411aYesanswers only an omitted or zero parameter
libghostty-vt0f171f6Yesanswers from its host; DA-5: also answers a non-zero parameter
ConEmubuild 230724, its documentationPartlylists ESC [ c and ESC [ > c, no tertiary DA: ANSI escape codes

Validation

DA-1: Primary attributes

\e[c
|_____|
reply \e[?64;1;2;6;9;15;17;18;21;22;28c

DA-2: With the parameter zero

\e[0c
|_____|
reply \e[?64;1;2;6;9;15;17;18;21;22;28c

DA-3: Secondary attributes

\e[>c
|_____|
reply \e[>41;412;0c

DA-4: Tertiary attributes

\e[=c
|_____|
reply \eP!|00000000\e\\

DA-5: A non-zero parameter is not a request

\e[1c     # identifies the host; asks nothing
|_____|
reply none

libghostty-vt answers it as if it were a request. Its DA dispatch in stream.zig chooses primary, secondary or tertiary from the intermediate byte alone and never looks at the parameter. ECMA-48 makes a non-zero DA an identification of its sender, DEC STD 070 makes only an omitted or zero parameter a request, and xterm replies only when the parameter is zero or left out.

DA-6: DECID

\eZ
|_____|
reply \e[?64;1;2;6;9;15;17;18;21;22;28c
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.