Summary
qtermwidget should support OSC 133 Semantic Prompt escape sequences to enable modern terminal features like jump-to-prompt, select command output, and visual separation of commands.
Motivation
The OSC 133 protocol allows shells to annotate terminal output with escape sequences that mark the boundaries of prompts, user input, and command output. When a terminal emulator understands these sequences, users get:
- A jump-to-prompt keyboard shortcut to jump between prompts in scrollback history
- The ability to easily select just the output of a specific command
- A horizontal separator lines between commands to make dense terminal output easier to scan
- Error highlighting, where failed commands can be visually marked (e.g., red separator or bar) based on exit code
- Prompt notifications to detect when a long-running command finishes and the shell is ready for input
Konsole (which shares a common ancestor with qtermwidget) has had a full OSC 133 implementation for some time. Adding support to qtermwidget would bring QTerminal and other applications built on qtermwidget up to parity with modern terminal emulators.
OSC 133 Protocol
Shells emit the following escape sequences at key points in the prompt lifecycle:
| Sequence |
When |
Purpose |
ESC]133;A ST |
Before rendering the prompt |
Marks prompt start |
ESC]133;B ST |
After prompt, before user input |
Marks where user input begins |
ESC]133;C ST |
When user submits input (Enter) |
Marks start of command output |
ESC]133;D;exitcode ST |
After command completes |
Marks end of command output with exit code |
ESC]133;L ST |
Before prompt, if cursor not at column 0 |
Ensures prompt starts on a fresh line |
Additionally, N and P are variants of A for right-side and continuation prompts.
Proposed Implementation
Suggest the following proposed implementation:
- Data model (
Character.h): Add new constants to mark lines where semantic transitions occur: LINE_PROMPT_START, LINE_INPUT_START, LINE_OUTPUT_START, etc.
- Escape sequence parsing (
Vt102Emulation.cpp): Intercept OSC attribute 133 in the existing processWindowAttributeChange() method and dispatch to Screen based on the sub-command character (A/B/C/D/L/N/P).
- Screen state tracking (
Screen.h/cpp): Add a simple state machine to Screen that tracks the current semantic region (none/prompt/input/output) and sets the appropriate LINE_* flags on the current line when each OSC 133 sub-command is received.
- History storage (
History.h/cpp): Update HistoryScroll::addLine so that semantic flags survive in scrollback.
- Public API (
qtermwidget.h): Expose setSemanticHintsEnabled(bool) / semanticHintsEnabled() for toggling visual hints and commandFinished(int exitCode) signal so consuming applications (e.g., QTerminal) can react to command completion.
References
Summary
qtermwidget should support OSC 133 Semantic Prompt escape sequences to enable modern terminal features like jump-to-prompt, select command output, and visual separation of commands.
Motivation
The OSC 133 protocol allows shells to annotate terminal output with escape sequences that mark the boundaries of prompts, user input, and command output. When a terminal emulator understands these sequences, users get:
Konsole (which shares a common ancestor with qtermwidget) has had a full OSC 133 implementation for some time. Adding support to qtermwidget would bring QTerminal and other applications built on qtermwidget up to parity with modern terminal emulators.
OSC 133 Protocol
Shells emit the following escape sequences at key points in the prompt lifecycle:
ESC]133;A STESC]133;B STESC]133;C STESC]133;D;exitcode STESC]133;L STAdditionally,
NandPare variants ofAfor right-side and continuation prompts.Proposed Implementation
Suggest the following proposed implementation:
Character.h): Add new constants to mark lines where semantic transitions occur:LINE_PROMPT_START,LINE_INPUT_START,LINE_OUTPUT_START, etc.Vt102Emulation.cpp): Intercept OSC attribute 133 in the existingprocessWindowAttributeChange()method and dispatch toScreenbased on the sub-command character (A/B/C/D/L/N/P).Screen.h/cpp): Add a simple state machine toScreenthat tracks the current semantic region (none/prompt/input/output) and sets the appropriateLINE_*flags on the current line when each OSC 133 sub-command is received.History.h/cpp): UpdateHistoryScroll::addLineso that semantic flags survive in scrollback.qtermwidget.h): ExposesetSemanticHintsEnabled(bool)/semanticHintsEnabled()for toggling visual hints andcommandFinished(int exitCode)signal so consuming applications (e.g., QTerminal) can react to command completion.References