Skip to content

Report terminal color scheme via CSI 996 and Mode 2031 - #657

Closed
ayanamists wants to merge 3 commits into
dakra:mainfrom
ayanamists:fix-color-scheme-report
Closed

ayanamists wants to merge 3 commits into
dakra:mainfrom
ayanamists:fix-color-scheme-report

Conversation

@ayanamists

Copy link
Copy Markdown
Contributor

Summary

  • Answer CSI ? 996 n with the terminal's dark/light color scheme.
  • Emit CSI ? 997 after synchronized default colors change when Mode 2031 is enabled.
  • Classify the last synchronized ghostel-default background using Neovim's BT.601 midpoint convention.
  • Keep child OSC 11 overrides separate from the host color scheme.

Why

libghostty already parses CSI 996 and tracks Mode 2031, but Ghostel did not provide the color-scheme callback or send change reports. Multiplexers could therefore keep stale host color caches after an Emacs theme change.

Ghostel does not store a separate light/dark appearance value. Its protocol background is seeded from the resolved ghostel-default face, which users can customize independently from the rest of Emacs. CSI 996/997 therefore classify the most recently synchronized default background. Theme changes synchronize it through the existing hook; after changing ghostel-default directly, users can call ghostel-sync-theme.

The implementation deliberately reads the default background rather than the current OSC 11 override. An OSC 11 override belongs to the child-controlled terminal session and should not redefine the host terminal's appearance.

The RGB classification follows the same BT.601 luma and 0.5 midpoint convention used by Neovim's terminal background detection.

Testing

  • zig build --prefix .
  • zig build test
  • Native OSC test suite: 30/30 passed
  • git diff --check

ghostel stored DEC Mode 2031 but never implemented color-scheme DSR:
CSI ? 996 n was ignored, and theme changes did not emit CSI ? 997.
Multiplexers such as herdr therefore kept a stale OSC 11 cache.

Infer light/dark from the protocol background (same luma cutoff as
herdr), answer 996 from that, and write an unsolicited 997 from
ghostel--set-default-colors when 2031 is on.
Those are POSIX-only, so the CSI 996 child never printed READY on Windows.
@dakra

dakra commented Aug 30, 2026

Copy link
Copy Markdown
Owner

@ayanamists thanks.
I squashed your commits and merged them as part of PR #659

I didn't make a release yet, so if you want to use this feature you have to build the native module yourself until a release is made.

@dakra dakra closed this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants