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. Per Bothner’s semantic prompts proposal, 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 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
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | No | OSC is not among the controls it recognizes (§4.2) |
| VT510 | manual, 1st ed., 1993 | No | ignores an OSC string (chapter 4) |
| xterm | patch 412, xterm-411a | No | ignored |
| libghostty-vt | 0f171f6 | Yes | marks cells and tells the host through SEMANTIC_PROMPT (OSC133-2, OSC133-3) |
| Konsole | 26.11.70, a24c3d71 | Yes | |
| iTerm2 | 3.7.3, its documentation | Yes | describes the four marks in Proprietary Escape Codes |
| ConEmu | build 230724, its documentation | No | not 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