OSC 133 Semantic Prompt
Mark where a shell's prompt, the command typed at it, and the command's output begin and end.
OSC 133 ; Ps ST
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 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.
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