^[control-codes
live in libghostty-vt

Control sequences

DSR Device Status Report

View as Markdown

Ask the terminal for its status or for the cursor position, and get a report back.

CSI Ps n

CPR Active Position Report

CSI Pl ; Pc R
Defaults
Ps = 0
ECMA-48
§8.3.35 DSR – Device Status Report, p. 40
DEC STD 070
§4, ch. 5 Device Status Report, p. 35
VT220
§4.17.2 Device Status Report (DSR)
VT510
DSR—Device Status Reports

A host sends DSR to ask the terminal something, and the terminal answers by sending a sequence back. Ps says what is asked:

PsAsks forThe terminal answers
5its operating statusCSI 0 n, ready, or CSI 3 n, not working
6the cursor positionCSI Pl ; Pc R, a cursor position report

The answers 0 and 3 are themselves DSRs, sent the other way. A terminal that receives one has not been asked anything, and does not answer.

The cursor position report is CPR, defined in ECMA-48 §8.3.14 as Active Position Report, p. 35, in DEC STD 070 §5.4.4, p. 5-53, and in the VT510 manual as DSR—Cursor Position Report. Pl is the line and Pc the column, counting from 1. With origin mode on, DEC STD 070 counts them from the top and left margins instead, the same way CUP counts the position it is given, so a host can send a report straight back as a CUP.

DEC STD 070 sends its reports with the 8-bit CSI, 9B. libghostty-vt sends ESC [, as a terminal sending only 7-bit controls does.

DEC terminals answer many more Ps values, for the printer, the keyboard, and with a ? before the parameter (CSI ? 6 n is DECXCPR, the cursor position with the page number). libghostty-vt answers 5 and 6 only.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Yes§4.17.2 Device Status Report (DSR)
VT510manual, 1st ed., 1993YesDSR and DSR—Cursor Position Report
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yesanswers 5 and 6 only, with ESC [
kitty0.49.1, run in a VMPartlyfails DSR-3, DSR-4 of the 4 cases that show it working
foot1.28.0, run in a VMPartlyfails DSR-3 of the 4 cases that show it working
pyte0.8.2, run as a libraryPartlyfails DSR-3, DSR-4 of the 4 cases that show it working
xterm.js headless6.0.0, run as a libraryPartlyfails DSR-3, DSR-4 of the 4 cases that show it working
alacritty_terminal0.26.0, run as a libraryPartlyfails DSR-3 of the 4 cases that show it working
ConEmubuild 230724, its documentationYes5 and 6; ANSI escape codes
rxvt-unicode9.31, run in a VMPartlyfails DSR-3 of the 4 cases that show it working
VTE0.84.1, run as a libraryYespasses the 4 cases that show it working

Validation

DSR-1: Operating status

\e[5n
|_____|
reply \e[0n

DSR-2: Cursor position

\e[2;3H
\e[6n
|_____|
|_____|
|_____|
reply \e[2;3R

DSR-3: Counted from the margins in origin mode

\e[?69h   # allow left and right margins
\e[2;5s   # margins at columns 2 and 5
\e[2;4r   # region is lines 2 to 4
\e[?6h    # origin mode
\e[2;2H   # line 3, column 3 of the screen
\e[6n
|_____|
|_____|
|_____|
|_____|
cursor 3,3
reply \e[2;2R

DSR-4: With a wrap pending

ABCDE     # fills the line; a wrap is pending
\e[6n
|ABCDE|
|_____|
reply \e[1;5R

DSR-5: A report is not a question

\e[0n     # "ready", as a terminal would answer
\e[3n     # "not working"
|_____|
reply none
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.