Skip to content

Support for OSC 133 Semantic Prompt #630

Description

@basil

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:

  1. Data model (Character.h): Add new constants to mark lines where semantic transitions occur: LINE_PROMPT_START, LINE_INPUT_START, LINE_OUTPUT_START, etc.
  2. 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).
  3. 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.
  4. History storage (History.h/cpp): Update HistoryScroll::addLine so that semantic flags survive in scrollback.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions