# Request Mode (DECRQM)

> Ask the terminal whether a mode is set, and get a DECRPM report back.

- **Sequence:** `CSI ? Pd $ p`
- **DEC STD 070:** [§5.13.2 Request Mode, p. 5-193](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n447/mode/1up)
- **VT510:** [DECRQM—Request Mode - Host To Terminal](https://vt100.net/docs/vt510-rm/DECRQM.html)

A host sends DECRQM to ask whether one mode is set, and the terminal answers
with DECRPM, Report Mode. There are two forms, for the two kinds of mode:

| Ask | About | The answer |
| --- | --- | --- |
| `CSI Pa $ p` | an [ANSI mode](https://control-codes.page/ansi/index.html.md), one [SM](https://control-codes.page/csi/sm/index.html.md) and [RM](https://control-codes.page/csi/rm/index.html.md) set | `CSI Pa ; Ps $ y` |
| `CSI ? Pd $ p` | a [private mode](https://control-codes.page/modes/index.html.md), one [DECSET](https://control-codes.page/csi/decset/index.html.md) and [DECRST](https://control-codes.page/csi/decrst/index.html.md) set | `CSI ? Pd ; Ps $ y` |

`Ps` in the answer says what state the mode is in:

| `Ps` | The mode is |
| --- | --- |
| `0` | not recognized |
| `1` | set |
| `2` | reset |
| `3` | set, and cannot be changed |
| `4` | reset, and cannot be changed |

DECRPM is defined in
[DEC STD 070 §5.13.2, p. 5-195](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n449/mode/1up)
and in the VT510 manual as
[DECRPM—Report Mode](https://vt100.net/docs/vt510-rm/DECRPM.html). Both
manuals say a DECRQM asks about one mode at a time. DEC STD 070 sends the
answer with the 8-bit CSI; libghostty-vt sends `ESC [`, as it does for its
other reports.

DEC STD 070 says that every ANSI mode "defined in X3.64-1979" is reported as
set or reset. The ones a DEC terminal never implements, such as GATM (`1`),
SRTM (`5`) and VEM (`7`), are listed in DEC STD 070's VT420 table and the
VT510 manual's as always reset, so the answer for them is `4`, reset and
unchangeable. A mode the terminal does not recognize is reported as `0`;
DEC STD 070 also reports that way the DEC private modes that exist but
"cannot be set or reset from the host".

A host can save the modes it is about to change by asking about each one
first, and restore them afterwards with SM and RM. That is the use the VT510
manual gives for it.

## Validation

### DECRQM-1: A DEC mode that is reset

Input, one step per line:

```text
\e[?6$p   # origin mode?
```

Expected screen:

```text
|_____|
reply \e[?6;2$y
```

### DECRQM-2: The same mode, set

Input, one step per line:

```text
\e[?6h    # origin mode on
\e[?6$p
```

Expected screen:

```text
|_____|
reply \e[?6;1$y
```

### DECRQM-3: A mode that starts out set

Input, one step per line:

```text
\e[?25$p  # the cursor is shown at first
\e[?25l
\e[?25$p
```

Expected screen:

```text
|_____|
cursor-visible no
reply \e[?25;1$y\e[?25;2$y
```

### DECRQM-4: An ANSI mode

Input, one step per line:

```text
\e[4$p    # insert mode?
\e[4h
\e[4$p
```

Expected screen:

```text
|_____|
reply \e[4;2$y\e[4;1$y
```

### DECRQM-5: A DEC mode the terminal does not know

Input, one step per line:

```text
\e[?9999$p
```

Expected screen:

```text
|_____|
reply \e[?9999;0$y
```

### DECRQM-6: An ANSI mode that is always reset

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
\e[1$p    # GATM, guarded area transfer
```

Expected screen:

```text
|_____|
reply \e[1;4$y
```

libghostty-vt answers `\e[1;0$y`, not recognized. It reports only the ANSI
modes it implements, KAM, IRM, SRM and LNM, and `0` for every other one.
DEC STD 070 requires every X3.64 ANSI mode to be reported as set or reset,
and both its VT420 table and the VT510 manual's mark GATM permanently reset.
xterm answers `4` for GATM and the other unimplemented ANSI modes
([`do_ansi_rqm`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L5408-L5463)),
and esctest2's `test_DECRQM_ANSI_GATM` expects `4`.

---

This is the Markdown version of <https://control-codes.page/csi/decrqm/>. 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>.
