Skip to content

fix(terminal): gate xterm contrast correction by terminal background luminance (#7934) - #9599

Merged
AmethystLiang merged 3 commits into
mainfrom
dark-theme-contrast-gate
Jul 21, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
dark-theme-contrast-gate

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7934. Gates xterm's minimumContrastRatio by the terminal's composed background luminance instead of exposing a user setting: 4.5 on light backgrounds, disabled (1) on dark backgrounds.

Why

minimumContrastRatio: 4.5 was added in #5986 to rescue invisible white/bright-white ANSI text on light (white) backgrounds. But it was applied globally, so on dark themes it over-corrects — distorting/dulling vibrant ANSI colors that were already perfectly readable. That's the user complaint in #7934.

Why background luminance, not app theme mode (the first commit gated by mode; the second switches the signal): either theme slot can hold either kind of theme. With terminalUseSeparateLightTheme off ("match dark mode"), light app mode still renders the dark terminal theme — mode-gating would keep the over-correction exactly where #7934 complains about it. Conversely, a light theme selected as terminalThemeDark would lose the white-text rescue. Gating on isTerminalBackgroundLight() over the composed theme background (translucent backgrounds composited against the app surface) resolves both configurations correctly.

minimumContrastRatio is a pure render-side setting — it does not change buffer/cell data — so gating it is safe and requires no cross-process/SSH plumbing.

Visual comparison

Same ANSI output, same theme (Orca's default Ghostty dark), same xterm build — the only variable is minimumContrastRatio (4.5 = correction on, 1 = off):

xterm contrast correction on vs off, dark and light backgrounds

  • Dark theme, left (old behavior): xterm force-brightens the theme's dim gray (brightBlack #666666 is only ~2.4:1 against #282c34), so dim/secondary TUI text loses its hierarchy and reads like body text; red is washed toward pink; white-on-red/blue badge foregrounds get nudged.
  • Dark theme, right (this PR): the palette renders exactly as the theme author designed.
  • Light theme, bottom row: why the correction must stay on for light backgrounds — at 1, ANSI white/bright-white body text (how agent CLIs print) vanishes into the background; at 4.5 it's rescued to a readable gray. That's the original bug class the setting was added for in fix: improve terminal contrast in light themes (Tango Light + xterm minimumContrastRatio) #5986.

How dramatic the dark-side difference looks depends on the theme — palettes that already clear 4.5:1 barely change. Dim/secondary text is the case that's visibly wrong on virtually every dark theme.

In-app validation

The two Terminal settings previews rendering live in the app, confirming the gate resolves per background (unchanged behavior; captured while validating the code path):

Light Mode Preview — white background ⇒ minimumContrastRatio = 4.5 (correction on; ANSI white/bright-white body text stays readable):

Light Mode Preview in Terminal settings

Dark Mode Preview — dark background ⇒ minimumContrastRatio = 1 (correction off; vibrant ANSI palette preserved as the theme author designed):

Dark Mode Preview in Terminal settings

Changes (renderer-only)

  • terminal-appearance.ts — applyTerminalAppearance() now writes a value-gated minimumContrastRatio derived from isTerminalBackgroundLight(theme?.background, { appSurface: appearance.mode }), right alongside the existing options.theme gating. This path re-runs on every theme flip — including auto/system dark↔light — so live switching is handled for free.
  • pane-terminal-options.ts — buildDefaultTerminalOptions() keeps 4.5 as the initial value so the first paint on a light background never flashes low-contrast text before appearance-apply runs.
  • TerminalSettingsPreview.tsx — mirrors the same background-luminance gating so the settings preview matches live panes when the preview theme toggle flips.

Deliberately not touched: no GlobalSettings field, no settings UI, and src/main/daemon/headless-emulator.ts is left alone (the headless emulator mirrors options for buffer parity, and minimumContrastRatio has no effect on cell data).

Supersedes #7939

That PR took a "make it configurable" approach we decided against. Background-gating needs no new user-facing knob.

Trade-off

A poorly-designed dark theme with genuinely low-contrast ANSI colors is no longer auto-rescued. That trade is intentional — the reported problem is over-correction on dark backgrounds, where the global rescue was doing more harm than good.

Tests

  • terminal-appearance.test.ts — apply-path coverage asserting light ⇒ 4.5, dark ⇒ 1, re-gating on a live flip, plus the two mismatch configs: "match dark mode" (light app + dark terminal theme ⇒ 1) and a light theme filling the dark slot (⇒ 4.5).
  • pane-lifecycle.test.ts — updated the default-options test to document that 4.5 is the light-background initial value.
  • Typecheck (tsconfig.tc.web), oxlint, and oxfmt all clean.

Made with Orca 🐋

minimumContrastRatio: 4.5 (added in #5986 to rescue invisible
white/bright-white ANSI text on light backgrounds) was applied globally,
over-correcting vibrant ANSI colors on dark themes. Keep 4.5 on light
themes; disable it (1) on dark themes.

applyTerminalAppearance re-gates it in its per-pane loop, so live
auto/system dark<->light flips are handled for free. buildDefaultTerminalOptions
keeps 4.5 as the initial value so the first paint on a light theme never
flashes low-contrast text. Supersedes #7939.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Terminal contrast correction now uses 4.5 for light backgrounds and 1 otherwise. Pane appearance application updates the value only when needed, while the settings preview re-applies it when the resolved mode changes. Tests cover light and dark themes, live theme switching, composed backgrounds, and the initial default option.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses #7934 by switching minimumContrastRatio based on terminal background luminance and covers the affected renderer paths and tests.
Out of Scope Changes check ✅ Passed The changes stay focused on terminal contrast correction, shared helper logic, and tests, with no unrelated feature scope.
Title check ✅ Passed The title clearly summarizes the main change: gating xterm contrast correction by terminal background luminance.
Description check ✅ Passed It covers summary, visuals, testing, and rationale well, but omits the required AI Review Report, Security Audit, and Notes sections.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 54224828-ab03-487f-b7a6-a6a151c5b3ae

📥 Commits

Reviewing files that changed from the base of the PR and between ccd72f5 and 3484071.

📒 Files selected for processing (5)
  • src/renderer/src/components/settings/TerminalSettingsPreview.tsx
  • src/renderer/src/components/terminal-pane/terminal-appearance.test.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-options.ts

Contrast correction rescues white text on light backgrounds but over-corrects
on dark. The previous mode-based gate failed when the terminal theme didn't
match the app mode (e.g., terminalUseSeparateLightTheme=false). Now gates by
the theme's background luminance via isTerminalBackgroundLight() instead.
@AmethystLiang AmethystLiang changed the title fix(terminal): gate xterm contrast correction by theme mode (#7934) fix(terminal): gate xterm contrast correction by terminal background luminance (#7934) Jul 21, 2026
Centralizes the minimumContrastRatio gating logic (#7934) into a
dedicated module so both the settings preview and live terminal
appearance apply the same contrast-by-luminance rule, preventing drift.
Adds value-gating to skip redundant writes that would clear xterm's
contrast cache on re-applies.
@AmethystLiang
AmethystLiang merged commit 7154445 into main Jul 21, 2026
5 checks passed
AmethystLiang added a commit that referenced this pull request Jul 23, 2026
* fix(terminal): restore a dark-background contrast floor

Fully disabling xterm minimumContrastRatio on dark backgrounds (#9599)
left near-background body text unreadable — Antigravity paints #262b30
on #1e242a (~1.1:1). Keep light backgrounds at WCAG-AA 4.5 and use a
milder dark floor (3) so dark-on-dark body text is lifted without the
full light-bg correction strength.

Fixes #10104

* fix(terminal): extend dark-bg contrast floor to preview + mobile terminals

The dark-background minimumContrastRatio floor (#10104) is applied per
`new Terminal()` construction site. Beyond the live pane, agent output also
renders in the dashboard popout preview and the mobile WebView, which were
still at the floor-1 default, so Antigravity output stayed unreadable there.

- AgentTerminalPreview: gate via resolveTerminalMinimumContrastRatio
- mobile WebView: port the gate as resolveTerminalContrastFloor (Chrome-74 JS)
- tests: builtin-catalog guard + mobile vm-harness coverage

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…luminance (stablyai#7934) (stablyai#9599)

* fix(terminal): gate xterm contrast correction by theme mode (stablyai#7934)

minimumContrastRatio: 4.5 (added in stablyai#5986 to rescue invisible
white/bright-white ANSI text on light backgrounds) was applied globally,
over-correcting vibrant ANSI colors on dark themes. Keep 4.5 on light
themes; disable it (1) on dark themes.

applyTerminalAppearance re-gates it in its per-pane loop, so live
auto/system dark<->light flips are handled for free. buildDefaultTerminalOptions
keeps 4.5 as the initial value so the first paint on a light theme never
flashes low-contrast text. Supersedes stablyai#7939.

Co-authored-by: Orca <[email protected]>

* fix(terminal): gate contrast correction by terminal background luminance

Contrast correction rescues white text on light backgrounds but over-corrects
on dark. The previous mode-based gate failed when the terminal theme didn't
match the app mode (e.g., terminalUseSeparateLightTheme=false). Now gates by
the theme's background luminance via isTerminalBackgroundLight() instead.

* refactor(terminal): extract contrast correction gating into shared helpe

Centralizes the minimumContrastRatio gating logic (stablyai#7934) into a
dedicated module so both the settings preview and live terminal
appearance apply the same contrast-by-luminance rule, preventing drift.
Adds value-gating to skip redundant writes that would clear xterm's
contrast cache on re-applies.

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(terminal): restore a dark-background contrast floor

Fully disabling xterm minimumContrastRatio on dark backgrounds (stablyai#9599)
left near-background body text unreadable — Antigravity paints #262b30
on #1e242a (~1.1:1). Keep light backgrounds at WCAG-AA 4.5 and use a
milder dark floor (3) so dark-on-dark body text is lifted without the
full light-bg correction strength.

Fixes stablyai#10104

* fix(terminal): extend dark-bg contrast floor to preview + mobile terminals

The dark-background minimumContrastRatio floor (stablyai#10104) is applied per
`new Terminal()` construction site. Beyond the live pane, agent output also
renders in the dashboard popout preview and the mobile WebView, which were
still at the floor-1 default, so Antigravity output stayed unreadable there.

- AgentTerminalPreview: gate via resolveTerminalMinimumContrastRatio
- mobile WebView: port the gate as resolveTerminalContrastFloor (Chrome-74 JS)
- tests: builtin-catalog guard + mobile vm-harness coverage

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

[Feature] Minimum Contrast Ratio

1 participant