Skip to content

Add passive-observer and OSC 52 Policy controls in libvt #40

Done

Description

@tony

Summary

Wave 2 policy slice of #34 (gated on Wave 1 open Event base): add Policy.emit_replies: bool = True for passive stream observers, replace Policy.allow_clipboard_read: bool with a default-deny enum that emits ClipboardReadRequested(Event) instead of fabricating empty OSC 52 clipboard replies, remove unreferenced Policy.allow_checksum_report, and expose Terminal.enqueue_reply(data: bytes) plus Parser.at_ground_state.

Motivation

  • When Terminal mirrors a tmux -CC %output stream (Add byte-oriented TmuxControlParser and two-phase -CC PaneAttach #27), the tmux server has already answered pane DA and DSR queries; queueing a second set of replies on Terminal either leaks unread bytes or double-injects responses if forwarded.
  • src/libvt/terminal.py answers OSC 52 ; <sel> ; ? under Policy(allow_clipboard_read=True) with b"\x1b]52;{sel};\x1b\\" (claiming an empty clipboard rather than delegating to a host clipboard provider).
  • Policy.allow_checksum_report has zero references in src/libvt/terminal.py, and implementing DECRQCRA (CSI * y) would require per-cell extension state on ASCII ' ' cells in src/libvt/_grid.py with zero callers in libtmux or modern terminal peers.

Proposal

  • Add emit_replies: bool = True on Policy so emit_replies=False suppresses all automatic terminal reply generation (DA1/DA2/DA3, DSR, CPR, DECRPM, XTVERSION, DECRQSS, XTGETTCAP, CSI ? u, OSC 4/10–12 queries, and ?2031 notifications) while keeping screen mutations and Event emission intact; expose a passive-observer Policy preset in libvt.contrib.tmux.profile.
  • Replace allow_clipboard_read: bool = False on Policy with clipboard_read: ClipboardReadPolicy = ClipboardReadPolicy.IGNORE (IGNORE drops OSC 52 ; <sel> ; ?; EMIT_EVENT emits ClipboardReadRequested(selection=...) with zero fabricated reply bytes), and add Terminal.enqueue_reply(data: bytes) so a host driver that services ClipboardReadRequested can inject a real OSC 52 response into the single reply queue.
  • Delete allow_checksum_report from Policy before 0.1.0, leaving CSI * y (DECRQCRA) a parser-dispatched no-op.
  • Expose a read-only Parser.at_ground_state: bool property on Parser (state == ParserState.GROUND and no buffered multibyte UTF-8 sequence) so external stream multiplexers and recorders know when chunk boundaries are sequence-safe without exposing mutable internal checkpoints.

Alternatives

  • Passing a synchronous clipboard_provider: Callable[[str], bytes] callback on Policy: rejected because Policy is a frozen, hashable configuration value and host clipboard access in asyncio test drivers is often asynchronous.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions