Do not send unsolicited DSR 997 when DECSET 2031 is enabled
Summary
Mode 2031 (ColorPaletteUpdates) is defined to notify applications when the color scheme changes — it is not a query. PR #21 made DECSET 2031 synthesize an immediate DSR 997 report on enable. Applications that enable 2031 during startup without arranging to consume a response (e.g. Claude Code) have that CSI sequence leak into the shell input buffer as literal text like ?997;1n.
This matches the shape of the bug already fixed by #40 for DECSET 1004 (focus reporting): spontaneous reports on mode-enable are wrong, applications can query explicitly via DSR 996 if they want the current scheme.
Repro
In an affected cmux build on fish:
printf '\e[?2031h'; sleep 0.1; printf '\n'
Prints ?997;1n into the prompt. With this patch, nothing leaks.
Originally reported against cmux: manaflow-ai/cmux#2636.
Change
src/termio/stream_handler.zig: .report_color_scheme branch in setMode no longer emits a color scheme report on enable. The mode bit is still toggled so future palette changes notify normally.
Test
Adds test "enabling mode 2031 does not emit an immediate color scheme report" in the same file, mirroring the structure of the focus-report regression test from #40. Verifies:
- The mode bit is set after
setMode(.report_color_scheme, true). termio_messagedstays false.- The termio mailbox is empty.
Verification
Built GhosttyKit.xcframework locally with and without this patch. Confirmed printf '\e[?2031h' leaks ?997;1n on the control build and is silent on the patched build.
Refs: #40, manaflow-ai/cmux#2636.
Summary by cubic
Stop sending unsolicited DSR 997 when enabling DECSET 2031. The mode now only reports on color scheme changes, preventing ?997;1n from leaking into shell input.
- Bug Fixes
setMode(.report_color_scheme, ...)no longer sends an immediate report; only toggles the mode bit.- Added a test to ensure the mode is set, no termio message is sent, and the mailbox stays empty.
- Apps that need the current scheme can query via DSR 996.
Summary by CodeRabbit
-
Bug Fixes
- Corrected behavior when enabling mode 2031 so it no longer emits an immediate color scheme report.
-
Tests
- Added a unit test ensuring enabling mode 2031 enables the mode without producing any immediate terminal messages.