Skip to content

Make Event an open base class and normalize OSC 133 / OSC 633 #38

Done

Description

@tony

Summary

Wave 1 leaf slice of #34: convert Event from a closed type Event = ... union into an open nominal class Event base (kw_only=True, match_args=False) with an opt-in type KnownEvent = ... union, consolidate title and working-directory variants, and normalize OSC 133 plus VS Code OSC 633 shell-integration sequences. Landing the open Event base in Wave 1 unblocks ClipboardReadRequested in Wave 2 and notification events in #31 without breaking downstream match exhaustiveness.

Motivation

  • src/libvt/events.py defines type Event = ... as a closed union with no shared base class, so adding any new protocol event breaks downstream callers that annotate Event alongside typing.assert_never, and positional dataclass matching becomes brittle whenever an existing event gains an optional field.
  • Terminal emits OSC 133 prompt marks (PromptMark), whereas shells running under VS Code, Ghostty, and Kitty integrations emit OSC 633 (A/B/C/D zones, E;<command>[;<nonce>] with \xAB/\\ escaping, and P;Cwd=...), often pairing OSC 133 and OSC 633 on the exact same (abs_row, col) cell.

Proposal

  • Define @dataclass(frozen=True, slots=True, kw_only=True, match_args=False) class Event: in src/libvt/events.py as the nominal base of all concrete event dataclasses, change Terminal.drain_events() to return tuple[Event, ...], and export type KnownEvent = ... in src/libvt/events.py for callers that explicitly opt into exhaustive union checking.
  • Consolidate overlapping variants by adding a target enum field on TitleChanged (window, icon, or tmux ESC k rename) and a source enum field on WorkingDirectoryChanged (OSC 7 vs OSC 633 ; P ; Cwd=...).
  • Normalize OSC 133 and OSC 633 A/B/C/D into PromptZone (exit_code: int | None on COMMAND_END), parse OSC 633 ; E ; <cmd>[;<nonce>] into ShellCommandReported by splitting ; before unescaping \xAB (0x00–0x20, 0x3b) and \\, route 633;P;Cwd=... to WorkingDirectoryChanged and other Key=Value pairs to ShellPropertyChanged, deduplicate same-(abs_row, col, kind) 133+633 marks, and keep 633;E and 633;P out of StopOn.PROMPT_MARK.

Alternatives

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions