Skip to content

fix(tui): keep shaded panels without palette queries - #3

Merged
0xble merged 3 commits into
mainfrom
fix/tui-bg-fallback
Apr 11, 2026
Merged

0xble merged 3 commits into
mainfrom
fix/tui-bg-fallback

Conversation

@0xble

@0xble 0xble commented Apr 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • fall back to COLORFGBG and stable dark defaults when OSC default-color queries fail
  • keep subtle shaded surfaces visible when terminal color capability detection is unavailable
  • cover the fallback with unit tests and updated TUI snapshots

Verification

  • cargo test -p codex-tui
  • cr review --agent --type committed --base-commit HEAD~1

Summary by CodeRabbit

  • Bug Fixes
    • Improved color fallback so UI elements retain intended background/foreground when terminal palette info is missing.
    • Ensured chat composer renders a visible fallback background when terminal palette queries are unavailable.
    • Use COLORFGBG-derived defaults and fixed dark fallbacks for more reliable colors across terminals.
  • Tests
    • Added and expanded tests and snapshots to validate fallback color behavior and visual consistency.

@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Added terminal default color fallbacks (COLORFGBG parsing and fixed dark RGBs), introduced helpers to choose explicit RGB when stdout color level is Unknown, updated style functions to use them, and added tests including a UI snapshot asserting fallback background rendering for an empty ChatComposer.

Changes

Cohort / File(s) Summary
Terminal Palette Enhancements
codex-rs/tui/src/terminal_palette.rs
Added fixed dark RGB fallback constants, parsing of COLORFGBG to derive fallback fg/bg, updated default_fg()/default_bg() to prefer queried defaults → COLORFGBG → fixed defaults, and extended DefaultColors derives (Debug, Eq, PartialEq).
Style System Updates
codex-rs/tui/src/style.rs
Introduced subtle_surface_bg(...) and subtle_surface_bg_with_level(...); user_message_bg now delegates to these helpers to return explicit Color::Rgb when StdoutColorLevel::Unknown, otherwise uses best_color. Added unit tests for branching by color level.
Tests / UI Rendering
codex-rs/tui/src/bottom_pane/chat_composer.rs
Added unit test empty_composer_uses_shaded_background_without_terminal_palette_queries that renders an empty ChatComposer, asserts the content row retains a background style, and records an insta snapshot for fallback rendering.
Tests
codex-rs/tui/src/style.rs, codex-rs/tui/src/terminal_palette.rs
Added tests covering subtle_surface_bg_with_level behavior (Unknown vs known levels) and COLORFGBG parsing/fallback scenarios (last two numeric entries, no numeric codes, only background code).

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant Term as Terminal Palette
    participant Style as Style System
    participant UI as UI Renderer

    rect rgba(100,150,200,0.5)
    Note over App,UI: Color determination and rendering flow

    App->>Term: query default colors
    alt Term returns defaults
        Term-->>Style: DefaultColors
    else Term missing defaults
        Term->>Term: parse COLORFGBG
        alt COLORFGBG yields numeric codes
            Term-->>Style: fallback fg/bg from COLORFGBG
        else
            Term-->>Style: fixed dark RGB defaults
        end
    end

    Style->>Style: subtle_surface_bg_with_level(target, level)
    alt level == Unknown
        Style-->>Style: return explicit Color::Rgb
    else
        Style-->>Style: return best_color(target)
    end

    Style-->>UI: styled widget (bg set)
    UI->>UI: render widget with background
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I peek the env when palettes hide,
parse numbers, choose a safe tide.
If levels are unknown, I paint with care,
RGB fallback—soft surface to share.
A snapshot saved, the pane glows fair.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: maintaining shaded panels when palette queries are unavailable.
Description check ✅ Passed The description provides a clear summary with verification steps, but does not follow the required template structure that mandates a link to a bug report or enhancement request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tui-bg-fallback

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
codex-rs/tui/src/style.rs (1)

49-57: Extract a shared helper to avoid test/production logic drift.

subtle_surface_bg_for re-implements the branch logic instead of reusing the production path. Consider extracting a single subtle_surface_bg_with_level(target, level) helper and calling it from both subtle_surface_bg and tests.

♻️ Suggested refactor
 fn subtle_surface_bg(target: (u8, u8, u8)) -> Color {
-    match stdout_color_level() {
-        // Some transports and test backends fail capability detection even though RGB colors still
-        // render correctly. Prefer a visible shaded surface over silently resetting to the
-        // terminal default.
-        StdoutColorLevel::Unknown => rgb_color(target),
-        _ => best_color(target),
-    }
+    subtle_surface_bg_with_level(target, stdout_color_level())
+}
+
+fn subtle_surface_bg_with_level(target: (u8, u8, u8), level: StdoutColorLevel) -> Color {
+    match level {
+        // Some transports and test backends fail capability detection even though RGB colors still
+        // render correctly. Prefer a visible shaded surface over silently resetting to the
+        // terminal default.
+        StdoutColorLevel::Unknown => rgb_color(target),
+        _ => best_color(target),
+    }
 }
@@
-    fn subtle_surface_bg_for(target: (u8, u8, u8), color_level: StdoutColorLevel) -> Color {
-        match color_level {
-            StdoutColorLevel::Unknown => rgb_color(target),
-            _ => best_color(target),
-        }
+    fn subtle_surface_bg_for(target: (u8, u8, u8), color_level: StdoutColorLevel) -> Color {
+        subtle_surface_bg_with_level(target, color_level)
     }
 }

Also applies to: 84-89

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@codex-rs/tui/src/style.rs` around lines 49 - 57, The test reimplements
production branching logic; extract a shared helper
subtle_surface_bg_with_level(target: (u8,u8,u8), level: StdoutColorLevel) that
contains the match/branch (using rgb_color or best_color) and then update
subtle_surface_bg to call subtle_surface_bg_with_level(target,
stdout_color_level()) and update the test helper (subtle_surface_bg_for or
similar) to call subtle_surface_bg_with_level with the desired level; also apply
the same extraction for the other duplicated block (the code around the other
subtle_surface_* helper).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@codex-rs/tui/src/style.rs`:
- Around line 49-57: The test reimplements production branching logic; extract a
shared helper subtle_surface_bg_with_level(target: (u8,u8,u8), level:
StdoutColorLevel) that contains the match/branch (using rgb_color or best_color)
and then update subtle_surface_bg to call subtle_surface_bg_with_level(target,
stdout_color_level()) and update the test helper (subtle_surface_bg_for or
similar) to call subtle_surface_bg_with_level with the desired level; also apply
the same extraction for the other duplicated block (the code around the other
subtle_surface_* helper).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc37faa3-8344-4301-aa3d-d0f8a3f03b99

📥 Commits

Reviewing files that changed from the base of the PR and between 3bedb99 and 327830c.

⛔ Files ignored due to path filters (15)
  • codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__approval_overlay__tests__network_exec_prompt.snap is excluded by !**/*.snap
  • codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__empty_with_fallback_background_debug.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__app_server_guardian_review_denied_renders_denied_request.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__app_server_mcp_startup_failure_renders_warning_history.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__approval_modal_exec.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__approval_modal_exec_multiline_prefix_no_execpolicy.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__approval_modal_exec_no_reason.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__approval_modal_patch.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__chatwidget_exec_and_status_layout_vt100_snapshot.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__chatwidget_tall.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__compact_queues_user_messages_snapshot.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__exec_approval_modal_exec.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__guardian_approved_exec_renders_approved_request.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__guardian_denied_exec_renders_warning_and_denied_request.snap is excluded by !**/*.snap
  • codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__review_queues_user_messages_snapshot.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • codex-rs/tui/src/bottom_pane/chat_composer.rs
  • codex-rs/tui/src/style.rs
  • codex-rs/tui/src/terminal_palette.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@codex-rs/tui/src/style.rs`:
- Around line 68-70: The test
user_message_style_uses_fallback_background_when_default_palette_is_unavailable
is currently brittle because assert_ne!(user_message_style().bg,
Some(Color::Reset)) still passes if bg is None; update the test to first assert
that user_message_style().bg is Some(...) (e.g.,
assert!(user_message_style().bg.is_some())) and only then assert_ne! against
Some(Color::Reset) to ensure a fallback background was actually applied; locate
the user_message_style function and its bg field and adjust the assertions
accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6c91fbc8-168b-41ea-9014-177e3e6bf005

📥 Commits

Reviewing files that changed from the base of the PR and between 327830c and 644a131.

📒 Files selected for processing (1)
  • codex-rs/tui/src/style.rs

Comment thread codex-rs/tui/src/style.rs Resolved
@0xble

0xble commented Apr 11, 2026

Copy link
Copy Markdown
Owner Author

Stacked follow-up: #4 tightens the fallback color parity after this mosh visibility fix.

Once #3 lands, #4 should rebase cleanly onto main and keep the same intent with a closer match to the normal panel shade.

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