^[control-codes
live in libghostty-vt

Operating system commands

OSC 133 Semantic Prompt

View as Markdown

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

OSC 133 ; Ps ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51

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.

PsMarks
Athe start of a prompt
Bthe end of the prompt, where the command being typed starts
Cthe end of the command, where its output starts
D ; statusthe end of the output, with the command’s exit status

Further ;-separated key=value options can follow. Per Bothner’s semantic prompts proposal, which most terminals that take these marks now follow, adds four more marks to FinalTerm’s:

PsMarks
La fresh line: a new line, unless the cursor is already at the start of one
Nthe same as A, but first ending any command still open with the same aid
Pthe 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
Ithe 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 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). 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

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aNoignored
libghostty-vt0f171f6Yesmarks cells and tells the host through SEMANTIC_PROMPT (OSC133-2, OSC133-3)
Konsole26.11.70, a24c3d71Yes
iTerm23.7.3, its documentationYesdescribes the four marks in Proprietary Escape Codes
ConEmubuild 230724, its documentationNonot in its ANSI escape codes

Validation

OSC133-1: The text appears as usual

\e]133;A\a
$\s
\e]133;B\a
ls
\e]133;C\a\r\n
out
\e]133;D;0\a
|$_ls__|
|out___|
cursor 2,4
reply none

OSC133-2: A default xterm marks no prompt

\e]133;A\a
$\s
\e]133;B\a
|$_____|
attr 1,1 semantic=output

OSC133-3: Nor input

\e]133;A\a
$\s
\e]133;B\a
ls
\e]133;C\a
|$_ls__|
attr 1,3 semantic=output
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.