Skip to content

Track committed Appearance across ?2026 holds and set_theme() #41

Done

Description

@tony

Summary

Wave 3 frame-state slice of #34 (gated on Wave 2 Policy.emit_replies): add an immutable Appearance record to src/libvt/style.py and commit it atomically inside Snapshot and _SyncState across ?2026 synchronized-output holds, wire Formatter to render snapshot appearance and DECSCNM (?5) reverse video, and add Terminal.set_theme() for host palette/scheme updates and ?2031 (CSI ? 997 ; Ps n) notifications.

Motivation

  • Terminal stores mutable _fg_rgb, _bg_rgb, _cursor_rgb, and _palette_overrides outside Snapshot, so OSC 4 and OSC 10 through OSC 12 mutations during a ?2026 BSU hold leak out of sync with Terminal.committed and ScreenDelta, and Formatter.format_snapshot() ignores dynamic palette overrides when rendering ANSI or HTML output.
  • libvt tracks mode ?2031 (DECSET 2031) and defines ColorScheme, yet Terminal has no set_theme() entry point to update host default colors (OSC 104 and OSC 110 through OSC 112 reset targets) or queue CSI ? 997 ; 1 n / CSI ? 997 ; 2 n unsolicited reports when the host theme changes.

Proposal

  • Define @dataclass(frozen=True, slots=True) class Appearance in src/libvt/style.py holding scheme: ColorScheme, effective default fg_rgb, bg_rgb, and cursor_rgb, sparse palette_overrides: tuple[tuple[int, tuple[int, int, int]], ...], and reverse_video: bool (DECSCNM ?5), and expose Snapshot.appearance: Appearance inside one committed frame bundle swapped atomically on ?2026 ESU (with appearance_revision tracked on _SyncState and ScreenDelta).
  • Separate host theme defaults (set via Terminal.set_theme(scheme=..., fg_rgb=..., bg_rgb=..., cursor_rgb=..., palette=...)) from guest OSC 4 and OSC 10 through OSC 12 overrides so OSC 104, OSC 110–112, DECSTR, and RIS restore the active host defaults cleanly.
  • Emit CSI ? 997 ; Ps n (Ps = 1 dark, Ps = 2 light) from Terminal.set_theme() when ?2031 is active (gated by Policy.emit_replies) on both scheme flips and host palette/default-color changes per Contour palette update notifications, and apply Appearance plus DECSCNM (?5) in Formatter.format_snapshot().

Alternatives

  • Reading Terminal's live _fg_rgb, _bg_rgb, and _palette_overrides inside Formatter: rejected because Formatter.format_snapshot(snap) operates on detached Snapshot values and live reads violate ?2026 frame atomicity.

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