# Cursor Up (CUU)

> Move the cursor up n lines.

- **Sequence:** `CSI Pn A`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.22 CUU – Cursor Up, p. 37](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n50/mode/1up)
- **DEC STD 070:** [§5.4.4 Cursor Up, p. 5-41](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n295/mode/1up)
- **VT220:** [§4.7 Cursor Positioning](https://vt100.net/docs/vt220-rm/chapter4.html#S4.7)
- **VT510:** [CUU—Cursor Up](https://vt100.net/docs/vt510-rm/CUU.html)

Move the cursor `Pn` lines up, keeping its column. A `0` is taken as `1`.

The cursor stops at the top margin if it started at or below it. A cursor
already above the top margin, which only absolute positioning can put there,
stops at the first line instead. CUU never scrolls: at the top margin it
simply goes no further, where [RI](https://control-codes.page/esc/ri/index.html.md) would scroll the region down.

Moving the cursor cancels any pending wrap. DEC STD 070 calls the pending
wrap the *Last Column Flag*, and its appendix on autowrap lists this among
the controls that should reset it
([§D.6.1, p. D-13](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n1199/mode/1up)); xterm clears it in
[`CursorUp`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/cursor.c#L271-L284), and libghostty-vt does the same.

[CUD](https://control-codes.page/csi/cud/index.html.md) goes the other way, and [CPL](https://control-codes.page/csi/cpl/index.html.md) moves up and
returns to the left margin as well.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | Yes | [§4.7 Cursor Positioning](https://vt100.net/docs/vt220-rm/chapter4.html#S4.7) |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | Yes | [CUU](https://vt100.net/docs/vt510-rm/CUU.html) |
| 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 |  |
| kitty | 0.49.1, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/kitty.json) | Yes | passes the 5 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) | Partly | fails CUU-3 of the 5 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) | Partly | fails CUU-4, CUU-5 of the 5 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 5 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) | Partly | fails CUU-3 of the 5 cases that show it working |
| ConEmu | build 230724, its [documentation](https://conemu.github.io/en/AnsiEscapeCodes.html) | Yes | lists `ESC [ lines A`: [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 5 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) | Yes | passes the 5 cases that show it working |

## Validation

### CUU-1: Up one line

Input, one step per line:

```text
\e[3;2H
\e[A
X
```

Expected screen:

```text
|_____|
|_X___|
|_____|
```

### CUU-2: Up n lines, stopping at the first line

Input, one step per line:

```text
\e[3;2H
\e[9A
X
```

Expected screen:

```text
|_X___|
|_____|
|_____|
```

### CUU-3: Stops at the top margin

Input, one step per line:

```text
\e[2;4r   # region is lines 2 to 4
\e[3;1H
\e[9A
X
```

Expected screen:

```text
|_____|
|X____|
|_____|
|_____|
```

### CUU-4: Above the top margin

Input, one step per line:

```text
\e[3;4r   # region is lines 3 and 4
\e[2;1H   # above it
\e[9A
X
```

Expected screen:

```text
|X____|
|_____|
|_____|
|_____|
```

### CUU-5: From a pending wrap

Input, one step per line:

```text
\e[2;1H
ABCDE     # fills the line; a wrap is pending
\e[A
X
```

Expected screen:

```text
|____X|
|ABCDE|
|_____|
```

---

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