# 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; the extension to the
original FinalTerm marks that most terminals now follow adds kinds of
prompt, such as a continuation prompt.

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.

## 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>.
