Repository navigation
Report the terminal color scheme via CSI 996 and Mode 2031 - #659
Merged
Merged
Conversation
libghostty parses CSI ? 996 n and tracks DEC Mode 2031, but ghostel provided no color-scheme callback and never pushed CSI ? 997 n, so multiplexers that cache OSC 11 colors kept stale values after an Emacs theme change. Answer 996 from the seeded default background (BT.601 luma, 0.5 midpoint) and push 997 from ghostel--set-default-colors when Mode 2031 is enabled. The PTY byte recorder test helper drops the POSIX-only tty and select modules so the new tests also run under ConPTY.
Report the scheme Emacs assigns to the ghostel-default background instead of a BT.601 luma cutoff: every OSC 11 consumer (Neovim, Emacs TUI, Emacs GUI) uses a different heuristic, so the terminal's own answer should match what Emacs is showing. The classification is stored on the terminal (the native process reads it through a pointer for the reader-thread 996 answer) and a 997 is pushed only when it changes, which also stops the double report per load-theme from enable-theme-functions firing for the `user' pseudo-theme. The 997 write happens after the terminal lock is released so a full PTY cannot stall the reader thread, and is best effort: a client can re-query with 996. disable-theme now re-syncs too, and ghostel-sync-theme skips buffers killed by re-entrant sentinels. The recorder, reply-probe and raw-echo test scripts share one reader/deadline loop in pty_setup.py; the recorder no longer truncates at the requested byte count, so duplicated reports fail the tests.
Move the terminal mutex to GhostelTerm and make NativeProcess borrow its owner. Separate handler terminal state from transport effects and lock terminal-dependent input encoding consistently.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #657 by @ayanamists — the first commit is that PR squashed verbatim; the second reworks it.
What
CSI ? 996 nwithCSI ? 997 ; 1 n(dark) /; 2 n(light).CSI ? 997 nto clients that enabled Mode 2031 when the classification changes (theme change,disable-theme,ghostel-sync-theme).Changes relative to #657
color-dark-p), so the terminal reports what Emacs itself considers dark:color-dark-pon theghostel-defaultbackground, passed to the module as a 4th argument ofghostel--set-default-colors.#808080is dark, as in Emacs. The Zig classifier and its (never compiled) unit test are gone.set-default-colors, andload-themefiresenable-theme-functionstwice (userpseudo-theme + theme), so every theme change produced two identical reports.term_mutexcould stall the reader thread on a full PTY; a write error no longer escapes the theme hook after the scheme is committed.disable-themere-syncs;ghostel-sync-themeskips buffers killed by re-entrant sentinels.test/fixtures/pty_setup.py.Verified live (both PTY backends)
996 answers under modus-vivendi/operandi and mid-grey backgrounds, exactly one 997 per light↔dark switch, per-buffer 2031 gating, dead-process write silent, OSC 11 override ignored, RIS keeps the scheme, OSC 10/11/4 palette sync unchanged.
Not addressed here
The pinned libghostty's
OSC 111(reset background) copiesdefaultintooverride, so after a child resets,OSC 11;?returns the stale colour across theme switches (fixed upstream). This — not 997, which Neovim 0.12 ignores — is what sets nvim's&background; needs a ghostty bump.Reloading an already-active theme emits two transient 997s (disable → enable); accepted as harmless.