# Device Status Report (DSR)

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

- **Sequence:** `CSI Ps n`
- **Defaults:** Ps = 0
- **ECMA-48:** [§8.3.35 DSR – Device Status Report, p. 40](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n53/mode/1up)
- **DEC STD 070:** [§4, ch. 5 Device Status Report, p. 35](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n238/mode/1up)
- **VT510:** [DSR—Device Status Reports](https://vt100.net/docs/vt510-rm/DSR.html)

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

| `Ps` | Asks for | The terminal answers |
| --- | --- | --- |
| `5` | its operating status | `CSI 0 n`, ready, or `CSI 3 n`, not working |
| `6` | the cursor position | `CSI 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](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n48/mode/1up),
in [DEC STD 070 §5.4.4, p. 5-53](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n307/mode/1up),
and in the VT510 manual as
[DSR—Cursor Position Report](https://vt100.net/docs/vt510-rm/DSR-CPR.html).
`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](https://control-codes.page/csi/cup/index.html.md) 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.

## Validation

### DSR-1: Operating status

Input, one step per line:

```text
\e[5n
```

Expected screen:

```text
|_____|
reply \e[0n
```

### DSR-2: Cursor position

Input, one step per line:

```text
\e[2;3H
\e[6n
```

Expected screen:

```text
|_____|
|_____|
|_____|
reply \e[2;3R
```

### DSR-3: Counted from the margins in origin mode

Input, one step per line:

```text
\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
```

Expected screen:

```text
|_____|
|_____|
|_____|
|_____|
cursor 3,3
reply \e[2;2R
```

### DSR-4: With a wrap pending

Input, one step per line:

```text
ABCDE     # fills the line; a wrap is pending
\e[6n
```

Expected screen:

```text
|ABCDE|
|_____|
reply \e[1;5R
```

### DSR-5: A report is not a question

Input, one step per line:

```text
\e[0n     # "ready", as a terminal would answer
\e[3n     # "not working"
```

Expected screen:

```text
|_____|
reply none
```

---

This is the Markdown version of <https://control-codes.page/csi/dsr/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
