Skip to content

DSR — Device Status Report

SequenceCSI <Ps> n
Bytes0x1B 0x5B <Ps> 0x6E
CategoryCSI
MnemonicDSR
Otty support✓ Implemented (Ps = 5, 6)

Description

A host program asks the terminal about its state and the terminal answers by writing a reply back up the PTY. Otty answers two queries immediately:

QueryReplyMeaning
CSI 5 nCSI 0 nTerminal is ready / OK (no malfunction).
CSI 6 nCSI <row> ; <col> RCursor Position Report (CPR). row / col are 1-based.

The CSI 6 n form is the one most programs care about: it's how a shell or TUI discovers where the cursor actually landed after printing text — for example to detect whether a prompt left a trailing partial line, or to measure the width of already-emitted output.

Example

bash
# Ask for the cursor position. The reply (e.g. `\e[12;1R`) is written to the
# terminal's input, so in a raw-mode program you'd read it back from stdin.
printf '\e[6n'

# Ask whether the terminal is OK — reply is `\e[0n`.
printf '\e[5n'

Because the reply arrives on the same channel as keyboard input, capturing it requires the program to put the terminal in raw mode and read stdin; you won't see the response if you just run the printf at an interactive shell prompt (the shell consumes it).

Not supported

  • DECXCPR (CSI ? 6 n) — the DEC private variant that adds a page number, replying CSI ? <row> ; <col> ; <page> R. Otty implements only the standard CSI 6 n form above. Single-page terminals essentially never need DECXCPR.
  • Other Ps values (e.g. printer / keyboard / locator status) are not answered.

Notes

  • The reply is sent as a PTY write, ordered with respect to other output the terminal generates.
  • Positions are reported relative to the viewport (or the scrolling region when origin mode DECOM / ?6 is active), matching how CUP interprets them.

Otty