# Shell Integration (OSC 133)

> Mark where a shell's prompt, the command typed at it, and the command's output begin and end.

- **Sequence:** `OSC 133 ; Ps ST`
- **ECMA-48:** [§8.3.89 OSC – Operating System Command, p. 51](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n64/mode/1up)

A shell that sends these marks the parts of what it writes, so that the
terminal knows where each prompt, each command and each command's output
are. With that, a terminal can jump from prompt to prompt, select one
command's output, or tell whether the last command failed.

| `Ps` | Marks |
| --- | --- |
| `A` | the start of a prompt |
| `B` | the end of the prompt, where the command being typed starts |
| `C` | the end of the command, where its output starts |
| `D ; status` | the end of the output, with the command's exit status |

Further `;`-separated `key=value` options can follow. Per Bothner's
[semantic prompts proposal](https://gitlab.freedesktop.org/Per_Bothner/specifications/-/blob/4d2e1d75d4861a1d924895e106f8f016880e12a7/proposals/semantic-prompts.md), which most terminals that take these marks
now follow, adds four more marks to FinalTerm's:

| `Ps` | Marks |
| --- | --- |
| `L` | a *fresh line*: a new line, unless the cursor is already at the start of one |
| `N` | the same as `A`, but first ending any command still open with the same `aid` |
| `P` | the start of a prompt, after `A` or `N`, or where another one begins; `k` says which kind: `i`, the primary prompt and the default, `r` for a right-hand prompt, and `c` or `s` for a continuation line |
| `I` | the same as `B`, but the input ends at the end of the line |

and these options: `aid`, an identifier for the application, which lets
commands nest; `cl`, on `A` or `N`, asking the terminal to turn clicks in
the input into cursor movement; and `err`, on `D`, an error code that is a
string, empty for success, which takes precedence over the exit status. `A`
itself also starts with a fresh line, and acts as if followed by
`P ; k=i`.

They came from FinalTerm, which is defunct; iTerm2's
[escape code documentation](https://iterm2.com/documentation-escape-codes.html)
now describes the four marks and how it interprets them. They are not
xterm's, and a default xterm ignores them
([the OSC numbers it knows](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L3476-L3504)).
The cases follow xterm.

libghostty-vt marks each cell as part of a prompt, of input, or of output,
which the `semantic` word in an `attr` line checks, and tells its host
through the `SEMANTIC_PROMPT` callback. Cells are output unless marked. The
cases that check for no marks are known differences.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | No | OSC is not among the controls it recognizes ([§4.2](https://vt100.net/docs/vt220-rm/chapter4.html#S4.2)) |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | No | ignores an OSC string ([chapter 4](https://vt100.net/docs/vt510-rm/chapter4.html)) |
| xterm | patch 412, [xterm-411a](https://github.com/ThomasDickey/xterm-snapshots/tree/xterm-411a) | No | ignored |
| libghostty-vt | [0f171f6](https://github.com/ghostty-org/ghostty/tree/0f171f650a1cbbd6df4a2573b6b0c7de57cc6d90) | Yes | marks cells and tells the host through `SEMANTIC_PROMPT` (OSC133-2, OSC133-3) |
| Konsole | 26.11.70, [a24c3d71](https://invent.kde.org/utilities/konsole/-/tree/a24c3d71be3684f24d030aa2dbe9bd723d985233) | Yes |  |
| iTerm2 | 3.7.3, its documentation | Yes | describes the four marks in [Proprietary Escape Codes](https://iterm2.com/documentation-escape-codes.html) |
| ConEmu | build 230724, its [documentation](https://conemu.github.io/en/AnsiEscapeCodes.html) | No | not in its [ANSI escape codes](https://conemu.github.io/en/AnsiEscapeCodes.html) |

## Validation

### OSC133-1: The text appears as usual

Input, one step per line:

```text
\e]133;A\a
$\s
\e]133;B\a
ls
\e]133;C\a\r\n
out
\e]133;D;0\a
```

Expected screen:

```text
|$_ls__|
|out___|
cursor 2,4
reply none
```

### OSC133-2: A default xterm marks no prompt

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

Input, one step per line:

```text
\e]133;A\a
$\s
\e]133;B\a
```

Expected screen:

```text
|$_____|
attr 1,1 semantic=output
```

### OSC133-3: Nor input

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

Input, one step per line:

```text
\e]133;A\a
$\s
\e]133;B\a
ls
\e]133;C\a
```

Expected screen:

```text
|$_ls__|
attr 1,3 semantic=output
```

---

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