(project-conformance)=

# Control-Function Conformance

Per-profile control-function and mode conformance derived from
{mod}`libvt.codec`, {mod}`libvt.modes`, and {mod}`libvt.profiles`, verified
against the recorded differential corpus in `tests/fixtures/ghostty_corpus/`
and compiled `libghostty-vt` (`LIBGHOSTTY_VT_PATH`).

Status values:

- **Supported**: Implemented across profiles per ECMA-48, DEC STD 070, VT500, or
  the referenced host protocol.
- **Partial**: Parsed and handled for core subcommands or event emission;
  unmodeled subcommands are ignored or reported as unhandled.
- **Ignored**: Parsed cleanly and ignored (or gated off by profile/policy).
- **Divergent**: Behavior varies intentionally across host profiles
  ({data}`~libvt.config.DEFAULT_PROFILE`,
  {data}`~libvt.profiles.GHOSTTY_PROFILE`,
  {data}`~libvt.profiles.KITTY_PROFILE`,
  {data}`~libvt.profiles.XTERM_PROFILE`,
  {data}`~libvt.profiles.LINUX_CONSOLE_PROFILE`, and
  {func}`~libvt.contrib.tmux.profile.tmux_profile`).

## C0 Controls

| Mnemonic | Byte | Status | Profile notes & test modules |
| --- | --- | --- | --- |
| `BEL` | `0x07` | Supported | Emits `Bell` and terminates `OSC`; `tests/test_terminal.py` |
| `BS` | `0x08` | Supported | Clears `pending_wrap` (or steps back under `?45`); `tests/test_screen.py` |
| `HT` | `0x09` | Supported | Advances to next tab stop or right margin; `tests/test_screen.py` |
| `LF` | `0x0A` | Supported | Line feed (adds `CR` under `LNM`); `tests/test_terminal.py` |
| `VT` | `0x0B` | Supported | Treated as `LF` per ECMA-48/xterm; `tests/test_differential_ghostty.py` |
| `FF` | `0x0C` | Supported | Treated as `LF` per ECMA-48/xterm; `tests/test_differential_ghostty.py` |
| `CR` | `0x0D` | Supported | Moves cursor to left margin and clears `pending_wrap`; `tests/test_screen.py` |
| `SO` | `0x0E` | Supported | Shifts `GL` to `G1` (`LINUX_CONSOLE_PROFILE` defaults `G1` to `'0'`); `tests/test_terminal.py` |
| `SI` | `0x0F` | Supported | Shifts `GL` to `G0`; `tests/test_terminal.py` |

## ESC, DCS, and APC Sequences

| Family | Mnemonic | Status | Profile notes & test modules |
| --- | --- | --- | --- |
| `ESC` | `SCS` | Supported | Designates `G0`–`G3` (`'B'`, `'0'`, `'A'`, `'U'` CP437 in `latin-1`); `tests/test_terminal.py` |
| `ESC` | `DOCS` | Divergent | `ESC % G` / `ESC % @` honored when `ScreenBehavior.allow_encoding_switch` is true (`LINUX_CONSOLE_PROFILE`); `tests/test_terminal.py` |
| `DCS` | `SIXEL` | Divergent | Tracks cell-aligned placements (respects `DECSDM` `?80`); `tmux_profile < 3.9` uses `sixel_erase_policy="whole_image"` vs `"cell_mask"`; `tests/test_graphics.py` |
| `DCS` | `DECRQSS` | Divergent | Replies with active SGR/margins/style; disabled on `LINUX_CONSOLE_PROFILE` and `tmux_profile < 3.6`; `tests/test_terminal.py` |
| `DCS` | `XTGETTCAP` | Divergent | Replies with hex-encoded capabilities; disabled on `LINUX_CONSOLE_PROFILE` and `tmux_profile`; `tests/test_terminal.py` |
| `APC` | `KITTY_GFX` | Supported | Tracks Kitty graphics `APC G` placements and responses; `tests/test_graphics.py` |

## CSI Control Functions

| Final / Form | Mnemonic | Status | Profile notes & test modules |
| --- | --- | --- | --- |
| `CSI @` | `ICH` | Supported | Inserts BCE blanks within active margins; `tests/test_screen.py` |
| `CSI A` | `CUU` | Supported | Moves cursor up within scroll margins; `tests/test_screen.py` |
| `CSI B` | `CUD` | Supported | Moves cursor down within scroll margins; `tests/test_screen.py` |
| `CSI C` | `CUF` | Supported | Moves cursor right within active margins; `tests/test_screen.py` |
| `CSI D` | `CUB` | Supported | Moves cursor left within active margins; `tests/test_screen.py` |
| `CSI E` | `CNL` | Supported | Moves cursor down and to left margin; `tests/test_differential_ghostty.py` |
| `CSI F` | `CPL` | Supported | Moves cursor up and to left margin; `tests/test_differential_ghostty.py` |
| `CSI G` | `CHA` | Supported | Sets cursor column (1-based); `tests/test_screen.py` |
| `CSI H` | `CUP` | Supported | Sets cursor `(row, col)` honoring `DECOM`; `tests/test_screen.py` |
| `CSI I` | `CHT` | Supported | Advances `Pn` tab stops; `tests/test_differential_ghostty.py` |
| `CSI J` | `ED` | Divergent | `ED 3` clears scrollback on alt screen for `XTERM_PROFILE`, `KITTY_PROFILE`, and `tmux_profile`; `tmux_profile` scrolls primary on `ED 2` (`ed2_scrolls_primary_to_history=True`) and uses `pending_wrap_phantom_col=True`; `GHOSTTY_PROFILE` preserves history wrap (`erase_severs_history_wrap=False`); `tests/test_screen.py` |
| `CSI K` | `EL` | Divergent | BCE erase in line; scalar `text_used` retains earlier `ECH` blank spans after interior `ECH` (unlike Ghostty's per-cell tag); `tmux_profile` sets `pending_wrap_phantom_col=True` and `GHOSTTY_PROFILE` sets `erase_severs_history_wrap=False`; `tests/test_differential_ghostty.py` |
| `CSI L` | `IL` | Divergent | Inserts lines within scroll region; `tmux_profile` preserves cursor column (`il_dl_resets_col=False`); `tests/test_screen.py` |
| `CSI M` | `DL` | Divergent | Deletes lines within scroll region; `tmux_profile` preserves cursor column (`il_dl_resets_col=False`); `tests/test_screen.py` |
| `CSI P` | `DCH` | Supported | Deletes characters within active margins; `tests/test_screen.py` |
| `CSI S` | `SU` | Divergent | Scrolls region up (pushes primary scrollback when full-screen; `tmux_profile` also pushes to history when `top > 0` via `top_margin_scrolls_to_history=True`); `tests/test_screen.py` |
| `CSI T` | `SD` | Supported | Scrolls region down; `tests/test_screen.py` |
| `CSI X` | `ECH` | Supported | Erases `Pn` cells with current BCE background; `tests/test_differential_ghostty.py` |
| `CSI Z` | `CBT` | Divergent | Backward tab stops; `GHOSTTY_PROFILE` and `XTERM_PROFILE` preserve `pending_wrap` (`cbt_preserves_pending_wrap=True`); `tests/test_screen.py` |
| `` CSI ` `` | `HPA` | Supported | Horizontal position absolute; `tests/test_differential_ghostty.py` |
| `CSI a` | `HPR` | Divergent | Horizontal position relative; ignored on `tmux_profile` (`hpr_vpr_enabled=False`); `tests/test_differential_ghostty.py` |
| `CSI b` | `REP` | Divergent | Repeats previous printable cluster; `GHOSTTY_PROFILE` uses `rep_uses_last_graphic=True` and `tmux_profile < 3.9` sets `rep_wraps=False`; `tests/test_terminal.py` |
| `CSI c` | `DA1` | Divergent | Emits `Profile.identity.da1` (silent when `Policy.emit_replies=False`); `tests/test_terminal.py` |
| `CSI d` | `VPA` | Supported | Vertical position absolute; `tests/test_differential_ghostty.py` |
| `CSI e` | `VPR` | Divergent | Vertical position relative; ignored on `tmux_profile` (`hpr_vpr_enabled=False`); `tests/test_differential_ghostty.py` |
| `CSI f` | `HVP` | Supported | Same positioning semantics as `CUP`; `tests/test_screen.py` |
| `CSI g` | `TBC` | Supported | Clears current or all tab stops (`0`/`3`); `tests/test_differential_ghostty.py` |
| `CSI h` | `SM` | Supported | Sets ANSI modes (`IRM`, `LNM`); `tests/test_terminal.py` |
| `CSI l` | `RM` | Supported | Resets ANSI modes (`IRM`, `LNM`); `tests/test_terminal.py` |
| `CSI m` | `SGR` | Supported | Attributes, 16/256/RGB colors, T.416 `:` subparameters, underline styles/colors; `tests/test_differential_ghostty.py` |
| `CSI n` | `DSR` | Supported | Device status (`5n`), cursor position (`6n`), color-scheme query (`?996n`); `tests/test_terminal.py` |
| `CSI q` | `XTVERSION/DECSCUSR` | Divergent | `CSI > q` (`XTVERSION`) emits `Profile.identity.xtversion`; `CSI Ps SP q` sets cursor shape; `tests/test_terminal.py` |
| `CSI r` | `DECSTBM` | Supported | Sets top/bottom scroll margins and homes cursor; `tests/test_screen.py` |
| `CSI s` | `DECSLRM/SCOSC` | Divergent | Sets left/right margins when `DECLRMM` (`?69`) is active (disabled on `LINUX_CONSOLE_PROFILE` and `tmux_profile`), else saves cursor; `tests/test_screen.py` |
| `CSI t` | `XTWINOPS` | Partial | Supports title stack push/pop (`22`/`23`) and pixel/cell geometry reports (`14`/`16`/`18`); ignores window-manager move/resize requests; `tests/test_terminal.py` |
| `CSI u` | `SCORC/KITTY_KBD` | Divergent | Restores cursor (`CSI u`); `CSI > / < / = / ? u` (`KITTY_KBD`) disabled on `XTERM_PROFILE`, `LINUX_CONSOLE_PROFILE`, and `tmux_profile`; `tests/test_input.py` |
| `CSI ? h` | `DECSET` | Supported | Sets supported DEC private modes; `tests/test_terminal.py` |
| `CSI ? l` | `DECRST` | Supported | Resets supported DEC private modes; `tests/test_terminal.py` |
| `CSI ? $ p` | `DECRQM` | Supported | Reports mode status (`0`–`4`) honoring `is_private_mode_supported`; `tests/test_terminal.py` |
| `CSI > q` | `XTVERSION` | Divergent | Emits `DCS > \| <xtversion> ST` when `Profile.identity.xtversion` is non-empty; `tests/test_terminal.py` |
| `CSI " q` | `DECSCA` | Supported | Marks subsequent cells protected/unprotected against `DECSED`/`DECSEL`; `tests/test_screen.py` |
| `CSI ? J` | `DECSED` | Supported | Selective erase in display respecting `DECSCA`; `tests/test_screen.py` |
| `CSI ? K` | `DECSEL` | Supported | Selective erase in line respecting `DECSCA`; `tests/test_screen.py` |
| `CSI ? s` | `XTSAVE` | Divergent | Saves current DEC private mode values; ignored on `tmux_profile` (`xtsave_enabled=False`); `tests/test_input.py` |
| `CSI ? r` | `XTRESTORE` | Divergent | Restores saved DEC private mode values; ignored on `tmux_profile` (`xtsave_enabled=False`); `tests/test_input.py` |
| `CSI ? S` | `XTSMGRAPHICS` | Divergent | Stateful color-register and pixel-geometry queries; disabled on `GHOSTTY_PROFILE`, `KITTY_PROFILE`, `LINUX_CONSOLE_PROFILE`, and default `TMUX_PROFILE` (`sixel=False`; geometry/set remain off when `sixel=True`); `tests/test_terminal.py` |

## OSC Sequences

| Code | Mnemonic | Status | Profile notes & test modules |
| --- | --- | --- | --- |
| `0` | `OSC 0 (icon+title)` | Supported | Updates window title and emits `TitleChanged`; `tests/test_terminal.py` |
| `1` | `OSC 1 (icon)` | Supported | Emits `TitleChanged(target=ICON)`; `tests/test_terminal.py` |
| `2` | `OSC 2 (title)` | Supported | Updates window title and emits `TitleChanged(target=WINDOW)`; `tests/test_terminal.py` |
| `4` | `OSC 4 (palette)` | Supported | Sets/queries indexed palette RGB entries; `tests/test_terminal.py` |
| `7` | `OSC 7 (cwd)` | Supported | Emits `WorkingDirectoryChanged(source=OSC7)`; `tests/test_terminal.py` |
| `8` | `OSC 8 (hyperlink)` | Supported | Attaches `Hyperlink` spans to written cells (cleared on BCE); `tests/test_terminal.py` |
| `9` | `OSC 9 (notification/progress)` | Supported | `OSC 9;4` updates root progress; other `OSC 9` emits `Notification`; `tests/test_status.py` |
| `10` | `OSC 10 (fg color)` | Supported | Sets/queries default foreground RGB (held across `?2026`); `tests/test_terminal.py` |
| `11` | `OSC 11 (bg color)` | Supported | Sets/queries default background RGB (held across `?2026`); `tests/test_terminal.py` |
| `12` | `OSC 12 (cursor color)` | Supported | Sets/queries cursor RGB (held across `?2026`); `tests/test_terminal.py` |
| `22` | `OSC 22 (pointer shape)` | Ignored | Parsed and dispatched to `UnhandledSequence` when recorded; `tests/test_codec.py` |
| `52` | `OSC 52 (clipboard)` | Supported | Emits `ClipboardWrite` and policy-gated `ClipboardReadRequested`; `tests/test_terminal.py` |
| `66` | `OSC 66 (text sizing)` | Ignored | Parsed and dispatched to `UnhandledSequence` when recorded; `tests/test_codec.py` |
| `99` | `OSC 99 (kitty notification)` | Supported | Reassembles chunked Kitty notifications into `Notification`; `tests/test_terminal.py` |
| `104` | `OSC 104 (reset palette)` | Supported | Resets one or all palette entries to profile defaults; `tests/test_terminal.py` |
| `110` | `OSC 110 (reset fg color)` | Supported | Resets foreground RGB to profile default; `tests/test_terminal.py` |
| `111` | `OSC 111 (reset bg color)` | Supported | Resets background RGB to profile default; `tests/test_terminal.py` |
| `112` | `OSC 112 (reset cursor color)` | Supported | Resets cursor RGB to profile default; `tests/test_terminal.py` |
| `133` | `OSC 133 (semantic prompt)` | Supported | Tracks monotonic `PromptZone` anchors across scrollback; `tests/test_terminal.py` |
| `633` | `OSC 633 (shell integration)` | Supported | Normalizes `A`–`D` prompts, `E` commands, and `P` properties; `tests/test_terminal.py` |
| `777` | `OSC 777 (notification)` | Supported | Parses `777;notify` into `Notification`; `tests/test_terminal.py` |
| `3008` | `OSC 3008 (context)` | Ignored | Parsed and dispatched to `UnhandledSequence` when recorded; `tests/test_codec.py` |
| `5522` | `OSC 5522 (mime clipboard)` | Ignored | Parsed and dispatched to `UnhandledSequence` when recorded; `tests/test_codec.py` |
| `7501` | `OSC 7501 (program status)` | Divergent | Tracks Rex program status tree and `?` queries; queries disabled when `Profile.identity.osc_7501_capabilities` is empty (`KITTY_PROFILE`, `XTERM_PROFILE`, `LINUX_CONSOLE_PROFILE`, `tmux_profile < 3.9`; `"?"` on `tmux_profile >= 3.9`); `tests/test_status.py` |

## ANSI and DEC Modes

| Mode | Code | Status | Profile notes & test modules |
| --- | --- | --- | --- |
| `IRM` | `4` | Supported | Insert mode shifts cells right within active margins; `tests/test_differential_ghostty.py` |
| `LNM` | `20` | Supported | Automatic newline adds `CR` on `LF`/`VT`/`FF`; `tests/test_differential_ghostty.py` |
| `DECCKM` | `?1` | Supported | Switches arrow keys between `CSI` and `SS3`; `tests/test_input.py` |
| `DECCOLM` | `?3` | Divergent | Gated by `?40` (`ALLOW_80_132`) by default; `CLEAR_ONLY` on `tmux_profile`, `IGNORE` on `LINUX_CONSOLE_PROFILE`; `tests/test_terminal.py` |
| `DECSCNM` | `?5` | Supported | Reverse video reflected in committed `Snapshot.appearance`; `tests/test_terminal.py` |
| `DECOM` | `?6` | Supported | Origin mode bounds `CUP`/`HVP` to scroll margins; `tests/test_screen.py` |
| `DECAWM` | `?7` | Supported | Auto-wrap mode (enabled by default); `tests/test_screen.py` |
| `AUTO_REPEAT` | `?8` | Supported | Controls legacy `KeyAction.REPEAT` emission; `tests/test_input.py` |
| `MOUSE_X10` | `?9` | Supported | X10 press-only mouse tracking; `tests/test_input.py` |
| `DECTCEM` | `?25` | Supported | Cursor visibility flag on `Snapshot.cursor.visible`; `tests/test_terminal.py` |
| `ALLOW_80_132` | `?40` | Divergent | Enables `DECCOLM`; unrecognized when `deccolm` is `IGNORE` or `CLEAR_ONLY`; `tests/test_terminal.py` |
| `REVERSE_WRAP` | `?45` | Supported | Allows `BS` to wrap backward across wrapped rows; `tests/test_screen.py` |
| `ALT_SCREEN_47` | `?47` | Divergent | Switches alternate screen without cursor save; `alternate_entry_preserves_cursor` selects home vs preserve (`tmux_profile` preserves), and `libvt` keeps per-screen cursors on exit (Ghostty shares cursor position across `?47`); `tests/test_differential_ghostty.py` |
| `APPLICATION_KEYPAD` | `?66` | Supported | Selects `SS3` keypad encoding; `tests/test_input.py` |
| `BACKARROW_IS_BS` | `?67` | Supported | Switches legacy `backspace` between `0x08` and `0x7F`; `tests/test_input.py` |
| `DECLRMM` | `?69` | Divergent | Left/right margin mode; disabled on `LINUX_CONSOLE_PROFILE` and `tmux_profile`; `tests/test_screen.py` |
| `DECSDM` | `?80` | Supported | SIXEL display scrolling mode; `tests/test_graphics.py` |
| `DECNCSM` | `?95` | Divergent | Preserves screen contents on `DECCOLM`; unrecognized when `deccolm` is `IGNORE` or `CLEAR_ONLY`; `tests/test_terminal.py` |
| `MOUSE_VT200` | `?1000` | Supported | VT200 button press/release tracking; `tests/test_input.py` |
| `MOUSE_BUTTON_EVENT` | `?1002` | Supported | Drag motion tracking with `MouseTracker` deduplication; `tests/test_input.py` |
| `MOUSE_ANY_EVENT` | `?1003` | Supported | Any-motion mouse reporting; `tests/test_input.py` |
| `FOCUS_EVENT` | `?1004` | Supported | Window focus-in/focus-out reporting; `tests/test_input.py` |
| `MOUSE_SGR` | `?1006` | Divergent | SGR mouse coordinates; `GHOSTTY_PROFILE` resets classic coordinates on inactive encoding reset (`reset_any_mouse_encoding=True`); `tests/test_input.py` |
| `ALTERNATE_SCROLL` | `?1007` | Supported | Maps wheel events to `CUU`/`CUD` on alt screen when mouse tracking is off; `tests/test_input.py` |
| `MOUSE_SGR_PIXELS` | `?1016` | Divergent | Pixel SGR coordinates; unrecognized when `cell_width_px <= 0` or `cell_height_px <= 0`; `tests/test_input.py` |
| `ALT_SCREEN_1047` | `?1047` | Divergent | Clears alternate screen on switch; `alternate_entry_preserves_cursor` selects home vs preserve (`tmux_profile` preserves), and `libvt` keeps per-screen cursors on exit (Ghostty shares cursor position across `?1047`); `tests/test_differential_ghostty.py` |
| `DECSC_1048` | `?1048` | Divergent | Saves/restores cursor; unrecognized when `separate_alt_save_cursor=True` (`tmux_profile`); `tests/test_terminal.py` |
| `ALT_SCREEN` | `?1049` | Divergent | Saves cursor and switches alternate screen; `DEFAULT_PROFILE` homes alt cursor, while `alternate_entry_preserves_cursor=True` (`tmux_profile`) preserves it (matching Ghostty) and `tmux_profile` also sets `separate_alt_save_cursor=True`; `tests/test_differential_ghostty.py` |
| `BRACKETED_PASTE` | `?2004` | Supported | Wraps paste frames in `CSI 200 ~ ... CSI 201 ~`; `tests/test_input.py` |
| `SYNCHRONIZED_OUTPUT` | `?2026` | Supported | Holds `Terminal.committed` atomically until `?2026l` or expiry; `tests/test_terminal.py` |
| `GRAPHEME_CLUSTERING` | `?2027` | Supported | Unicode 17 grapheme clustering (enabled by default); `tests/test_ucd.py` |
| `COLOR_SCHEME_UPDATES` | `?2031` | Supported | Emits `CSI ? 997 ; Ps n` on `Terminal.set_theme()`; `tests/test_terminal.py` |
| `IN_BAND_RESIZE` | `?2048` | Supported | Emits `CSI 48 ; rows ; cols ; hpx ; wpx t` on resize; `tests/test_terminal.py` |

## Running Compiled `libghostty-vt` Parity

The default test suite runs chunk-boundary prefix determinism over all recorded
`.jsonl` corpus traces in `tests/fixtures/ghostty_corpus/` without requiring a
native compiler. To run compiled `libghostty-vt` differential parity locally,
point `LIBGHOSTTY_VT_PATH` to a built `libghostty-vt` shared library:

```console
$ LIBGHOSTTY_VT_PATH=/path/to/libghostty-vt.so uv run pytest -m ghostty -v
```

When `LIBGHOSTTY_VT_PATH` is unset, `@pytest.mark.ghostty` tests skip. When
`LIBGHOSTTY_VT_PATH` is set to a missing path, `load_optional_ghostty_vt()`
raises {exc}`FileNotFoundError` so configured parity jobs fail visibly.
