Skip to content

Composer text becomes unreadable after live terminal theme switch #14105

Closed as duplicate

Description

@0xdeafbeef

Repro

  1. Start Codex TUI in a terminal with a dark theme.
  2. Type in the composer.
  3. Switch the terminal to a light theme without restarting Codex.
  4. Return focus to Codex and keep typing.

Actual

Composer input becomes nearly invisible, effectively white/light text on a white/light background.

Expected

Composer text should stay readable after a terminal theme change.

Suspected cause

The composer background is recomputed from terminal colors, but textarea text is rendered with default/inherited cell styling. After a dark -> light theme switch, stale
foreground styling can remain while the background updates, leaving the input white-on-white.

Relevant files

  • codex-rs/tui/src/bottom_pane/chat_composer.rs
  • codex-rs/tui/src/bottom_pane/textarea.rs
  • codex-rs/tui/src/tui/event_stream.rs

Before switch:

Image After: Image

Same after dark to light switches

Evidence:

Activity

  1. added
    bug
    CLI
    TUI
    on Mar 9, 2026
  2. removed
    CLI
    on Mar 9, 2026
  3. mvanhorn commented on Mar 10, 2026

    @mvanhorn

    Analysis & Root Cause

    I traced the rendering path through the TUI code.

    Root cause: terminal_palette.rs captures the terminal's foreground/background colors at startup (or palette construction time). When the terminal theme changes externally (dark -> light), ratatui widgets that use Color::Reset or no explicit color inherit the new terminal defaults correctly. But the composer input widget in public_widgets/composer_input.rs appears to use explicit or cached foreground colors derived from the original palette, creating a stale-color-on-new-background mismatch.

    Relevant files:

    • codex-rs/tui/src/terminal_palette.rs - initial color capture
    • codex-rs/tui/src/public_widgets/composer_input.rs - text rendering
    • codex-rs/tui/src/color.rs and codex-rs/tui/src/style.rs - color/style helpers
    • codex-rs/tui/src/bottom_pane/list_selection_view.rs - theme picker (syntax highlighting themes, separate concern)

    The pattern: Any widget that caches a resolved foreground color from the palette at init time will break on theme switch. The fix needs to address the root (palette staleness), not just the symptom (composer text).

    Proposed Fix

    Simplest approach: In the composer input widget, use Color::Reset for text foreground instead of a cached color value. This delegates color choice to the terminal, which always reflects the current theme. This is the lowest-risk fix and matches how most ratatui apps handle default text colors.

    More robust approach: Detect terminal theme changes via OSC 10/11 escape sequences (query terminal fg/bg colors) on each draw cycle or on SIGWINCH. If the resolved colors differ from the cached palette, rebuild the palette. This would fix the issue for all widgets, not just the composer.

    The simpler Color::Reset approach is probably right for a first fix - it solves the reported problem with minimal blast radius. Happy to submit a PR if invited.

  4. ctbeiser commented on Aug 13, 2026

    @ctbeiser

    I can confirm this is still extant. It's particularly a problem if you have long running tasks and use auto-light mode.

  5. piotrostr commented on Aug 26, 2026

    @piotrostr

    Working automatic reference implementation covering this repro is posted here: #38575 (comment)

    It includes both live DEC mode 2031 refresh and the stale composer foreground fix. Validated on Ghostty 1.2.3 through tmux 3.6a. No command or config surface.

    ~ codex & piotr

  6. lubosxyz commented on Sep 10, 2026

    @lubosxyz

    Additional reproduction on Codex CLI 0.154.0 (macOS arm64), observed while switching the terminal palette in Superset 1.27.0. Full RGB and syntax highlighting must remain enabled.

    In a controlled real-PTY replay of light → dark → light, the unmodified release issued OSC 11 background queries [1, 0, 0] across the three phases. Its message background stayed at the light-derived RGB (244,244,244) during the dark phase. This reproduces without depending on a host focus transition.

    A local experimental Unix patch, based on release commit 6b9826e3aa83b1a5947db50f4332cb9c65f1b340, periodically re-queries OSC 10/11 using the existing bounded probe and invalidates the viewport and rendering caches only when the RGB pair changes. Missing replies retain the last good palette and trigger a longer backoff. The event reader is paused during the query and consumed user input is replayed through the existing parser, including timeout/error paths.

    The candidate passed same-process light → dark → light checks for composer, diff preview, and unsaved syntax-theme preview. Message backgrounds changed (244,244,244) → (64,65,60) → (244,244,244). A Unicode bracketed paste interleaved with the OSC response remained intact. Explicit syntax themes and unsaved previews were preserved; automatic theme reconciliation was deferred until the popup closed.

    Two implementation pitfalls worth covering in any upstream fix:

    • OSC probing must preserve interleaved keyboard/paste input, including missing replies.
    • Restoring the configured syntax theme during a live palette change can silently overwrite an unsaved /theme preview.

    All five added Rust regression tests passed. The full TUI suite was not entirely green: 34 failures also reproduced with the patch removed; seven additional failures/timeouts under load passed when rerun in isolation. This is experimental local evidence, not a claim of an upstream-approved solution. DECSET 2031 support would provide event-driven notification in supporting terminals; a fallback still matters for hosts that only answer OSC queries.

    ⌘ codex & lubosxyz

  7. etraut-openai commented on Oct 12, 2026

    @etraut-openai
    Contributor

    (response from codex)

    Closing as a duplicate of #45163, which tracks the same unreadable composer after a live terminal theme change and explains the current startup-only palette cache. It is still unresolved there; no fix is being claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TUIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions