Skip to content

Refresh terminal colors after scheme changes - #1

Open
piotrostr wants to merge 1 commit into
mainfrom
fix/live-terminal-theme-refresh
Open

piotrostr wants to merge 1 commit into
mainfrom
fix/live-terminal-theme-refresh

Conversation

@piotrostr

Copy link
Copy Markdown
Owner

Why

Reference implementation for openai/codex. Upstream blocks external pull-request creation, so this PR is hosted in the fork for maintainer review and cherry-picking.

Codex probes OSC 10/11 once, then keeps that palette for the process lifetime. A long-running TUI therefore keeps stale composer and syntax colors after Ghostty changes theme, sometimes producing unreadable dark-on-dark or light-on-light text until Codex restarts.

Related: openai#18942, openai#14105, openai#38575.

How

  • Subscribe to DEC mode 2031 while the TUI owns the terminal and disable it during restoration.
  • Handle CSI ? 997 ; 1 n and CSI ? 997 ; 2 n through the crossterm event stream.
  • Defer the refresh to the app boundary, pause crossterm, re-query OSC 10/11, filter only valid color replies, replay interleaved typeahead, replace the palette cache, re-resolve the adaptive syntax theme, and force a full redraw.
  • Set composer foreground and background as a pair so default textarea styling cannot preserve stale foreground cells.
  • Keep behavior automatic. No command or config surface is added.

The crossterm event variant is in openai-oss-forks/crossterm#3. This branch temporarily pins that public implementation commit; the pin should move back to the OpenAI fork after the dependency PR merges.

Validation scope: Ghostty 1.2.3 through tmux 3.6a on macOS. Terminals that emit DEC mode 2031 reports should follow the same path; unsupported terminals ignore the mode and keep existing behavior.

Verification

  • Live automatic dark/light scheme switch in a long-running Codex session: passed on Ghostty 1.2.3 through tmux 3.6a.
  • just test -p codex-tui: 3976 passed, 6 skipped.
  • New PTY integration test proves DEC mode 2031 subscription, automatic OSC 10/11 re-query, palette update path, and preservation of interleaved typed input.
  • just fix -p codex-tui: passed.
  • just bazel-lock-update and just bazel-lock-check: passed.
  • Crossterm dependency tests, including all features: passed.

~ codex & piotr

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.

1 participant