# Locking Shift Two and Three (LS2, LS3)

> Switch the characters printed to the G2 or G3 set.

- **Sequence:** `ESC n`
- **ECMA-48:** [§8.3.78 LS2 – Locking-Shift Two, p. 49](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n62/mode/1up)
- **DEC STD 070:** [§3.8.3.1 Locking Shift Two, p. 3-75](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n179/mode/1up)
- **VT220:** [§4.4.3 Invoking Character Sets with Locking Shifts](https://vt100.net/docs/vt220-rm/chapter4.html#S4.4.3)
- **VT510:** [Table 4–8](https://vt100.net/docs/vt510-rm/chapter4.html#T4-8)

LS2 invokes the G2 set into GL, and LS3 (`ESC o`) the G3 set: everything
printed after it comes from that set, until another shift. They do for G2 and
G3 what [SO](https://control-codes.page/c0/so/index.html.md) does for G1, and [SI](https://control-codes.page/c0/so/index.html.md) undoes them by invoking
G0 again. G2 and G3 are filled with `ESC * F` and `ESC + F`.

LS3 is
[ECMA-48 §8.3.80, p. 50](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n63/mode/1up)
and [DEC STD 070 §3.8.3.1, p. 3-76](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n180/mode/1up).
DEC STD 070 says both are there "for interchange compatibility with ISO and
ANSI standards", and that they are "not to be used by conforming software".

LS1R, LS2R and LS3R (`ESC ~`, `ESC }` and `ESC |`) invoke G1, G2 and G3
into GR instead, the right half of the code table, `A1` to `FE`. That half
exists only where the input is 8-bit codes. libghostty-vt decodes its input
as UTF-8, where `A1` to `FE` are not bytes of their own but parts of
multi-byte characters. It accepts the three sequences and records the
choice, but `print` in `Terminal.zig` never consults GR, so they have no
effect.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | Yes | [§4.4.3 Invoking Character Sets with Locking Shifts](https://vt100.net/docs/vt220-rm/chapter4.html#S4.4.3), VT200 mode only |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | Yes | [LS](https://vt100.net/docs/vt510-rm/LS.html), Level 4 mode only |
| xterm | patch 412, [xterm-411a](https://github.com/ThomasDickey/xterm-snapshots/tree/xterm-411a) | Yes |  |
| libghostty-vt | [0f171f6](https://github.com/ghostty-org/ghostty/tree/0f171f650a1cbbd6df4a2573b6b0c7de57cc6d90) | Yes | LS1R, LS2R and LS3R are accepted but have no effect |
| kitty | 0.49.1, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/kitty.json) | No | fails the 3 cases that show it working |
| foot | 1.28.0, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/foot.json) | Yes | passes the 3 cases that show it working |
| pyte | 0.8.2, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/pyte.json) | No | fails the 3 cases that show it working |
| xterm.js headless | 6.0.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/xtermjs.json) | Yes | passes the 3 cases that show it working |
| alacritty_terminal | 0.26.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/alacritty.json) | No | fails the 3 cases that show it working |
| ConEmu | build 230724, its [documentation](https://conemu.github.io/en/AnsiEscapeCodes.html) | No | not in ConEmu's [ANSI escape codes](https://conemu.github.io/en/AnsiEscapeCodes.html) |
| rxvt-unicode | 9.31, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/urxvt.json) | Yes | passes the 3 cases that show it working |
| VTE | 0.84.1, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/vte.json) | No | fails the 3 cases that show it working |

## Validation

### LS2-1: G2 into GL, then back

Input, one step per line:

```text
\e*0      # G2 is DEC Special Graphics
\en       # LS2
qx
\x0f      # SI: G0 again
q
```

Expected screen:

```text
|─│q_______|
```

### LS2-2: G3 into GL, then back

Input, one step per line:

```text
\e+0      # G3 is DEC Special Graphics
\eo       # LS3
qx
\x0f      # SI: G0 again
q
```

Expected screen:

```text
|─│q_______|
```

### LS2-3: The shift lasts across lines

Input, one step per line:

```text
\e*0      # G2 is DEC Special Graphics
\en       # LS2
q\r\nq
\x0f      # SI
q
```

Expected screen:

```text
|─_________|
|─q________|
```

---

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