# Set Termcap Data (XTSETTCAP)

> Tell xterm which terminal description to take its function keys from.

- **Sequence:** `DCS + p Pt ST`
- **xterm:** [Device-Control functions](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

`DCS + p Pt ST` gives xterm the name of a terminal description, in
hexadecimal like the names [XTGETTCAP](https://control-codes.page/dcs/xtgettcap/index.html.md) takes. xterm looks
it up in the system's terminfo or termcap, and from then on, when its
keyboard is in *termcap* mode (`-tcap`, or `CSI ? 1050 h`), its function keys
send what that description says they send. An empty name, one that is not
in hexadecimal, or one that cannot be found rings the bell instead
([`XTSETTCAP`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L5166-L5170),
[`set_termcap`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/xtermcap.c#L624-L657)).
A default xterm allows it: its `disallowedTcapOps` names `SetTcap`, but that
list applies only when `allowTcapOps` is off, and it is on.

Its keyboard is not in termcap mode by default, so the only thing a case can
see is the bell. The cases follow xterm, and assume no terminal description
called `no-such-terminal` is installed.

libghostty-vt does not implement it, and consumes the string without ringing
the bell, so the cases that expect the bell are known differences.

## Validation

### XTSETTCAP-1: Nothing on screen

Input, one step per line:

```text
A
\eP+p787465726D\e\\  # xterm
B
```

Expected screen:

```text
|AB____|
cursor 1,3
reply none
```

### XTSETTCAP-2: An empty name rings the bell

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

Input, one step per line:

```text
\eP+p\e\\
```

Expected screen:

```text
|______|
bell 1
```

### XTSETTCAP-3: So does one it cannot find

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

Input, one step per line:

```text
\eP+p6E6F2D737563682D7465726D696E616C\e\\  # no-such-terminal
```

Expected screen:

```text
|______|
bell 1
```

---

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