# Bi-directional Support Mode (BDSM)

> Whether the terminal or the host handles bidirectional text.

- **Sequence:** `CSI 8 h`
- **ECMA-48:** [§7.2.1 BDSM – Bi-directional Support Mode, p. 21](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n34/mode/1up)

Mode 8 is one of the two modes the fifth edition of ECMA-48 added for
bidirectional text. Reset, control functions act on the presentation or
the data according to [DCSM](https://control-codes.page/ansi/dcsm/index.html.md); set, they act on the data, and
the device handles the bidirectional aspects of the text itself.

| State | ECMA-48 calls it | Meaning |
| --- | --- | --- |
| Reset, `CSI 8 l` | EXPLICIT | control functions act where DCSM says |
| Set, `CSI 8 h` | IMPLICIT | control functions act on the data, and the device handles bidirectional text itself |

Neither xterm nor libghostty-vt implements it. Both ignore `CSI 8 h` and
`CSI 8 l`, and both answer [DECRQM](https://control-codes.page/csi/decrqm/index.html.md) with `0`, not
recognized: the mode is not among the ones xterm's [`do_ansi_rqm`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L5408-L5463) answers for.

## Validation

### BDSM-1: Not recognized

Input, one step per line:

```text
\e[8$p
```

Expected screen:

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

### BDSM-2: Not recognized after it is set, either

Input, one step per line:

```text
\e[8h
\e[8$p
```

Expected screen:

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

---

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