Skip to content

feat(terminal): make minimum contrast ratio configurable - #7939

Closed
bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:fix/7934-minimum-contrast-ratio
Closed

bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:fix/7934-minimum-contrast-ratio

Conversation

@bbingz

@bbingz bbingz commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes xterm minimumContrastRatio user-configurable (issue #7934).

The hardcoded 4.5 in pane-terminal-options.ts boosts low-contrast ANSI text for accessibility, but can rewrite carefully chosen theme colors. Users can now set 1 (no correction) through 21 under Settings → Terminal → Rendering.

  • Default remains 4.5 so existing behavior is unchanged.
  • Applied on pane create and live appearance updates.
  • Settings preview follows the same value.

Test plan

  • vitest pane-lifecycle normalize/default tests
  • typecheck:tsc:node
  • Manual: Settings → Terminal → Rendering → set Minimum Contrast Ratio to 1; confirm theme colors render without boost
  • Manual: leave default 4.5; low-contrast white-on-light still readable
  • Manual: settings search finds “Minimum Contrast Ratio” / “contrast”

Fixes #7934

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@bbingz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: da4727ff-e654-47ed-8ee0-350f003f4429

📥 Commits

Reviewing files that changed from the base of the PR and between 362fdeecb52775c7a86b0d2798d139ee42303913 and 3f66cdd.

📒 Files selected for processing (2)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
📝 Walkthrough

Walkthrough

Adds a new terminalMinimumContrastRatio setting to GlobalSettings, with a default value of 4.5 and a documented range of 1–21. Introduces normalization constants and helper logic, wires the normalized value into terminal panes and the settings preview, adds a settings UI field and search metadata, and updates related tests and test settings helpers.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the summary and testing, but it is missing required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including screenshots/no visual change, AI review report, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: making terminal minimum contrast ratio configurable.
Linked Issues check ✅ Passed The PR satisfies #7934 by exposing minimumContrastRatio in settings, allowing 1-21, preserving the 4.5 default, and applying it in preview and panes.
Out of Scope Changes check ✅ Passed The code changes are focused on the requested terminal contrast setting and supporting tests/types, with no obvious unrelated additions.

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.

🧹 Nitpick comments (1)
src/renderer/src/components/settings/TerminalRenderingSection.tsx (1)

27-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace fragile searchEntries[1] index access with inline values.

The magic index 1 silently selects the wrong entry if the catalog is ever reordered. Additionally, contrastEntry?.keywords pulls in translated keywords from translateSearchKeyword, which conflicts with the convention of using English-only keywords in SearchableSetting for consistency across panes — the GPU Acceleration SearchableSetting above hardcodes English keywords directly.

Consider removing contrastEntry entirely and inlining the description via translate() and the keywords as an English-only array, matching the existing pattern.

♻️ Proposed refactor
-  const searchEntries = getTerminalRenderingSearchEntries()
-  // Why index 1: catalog order is GPU Acceleration, then Minimum Contrast Ratio.
-  const contrastEntry = searchEntries[1]
-
   return (
     <section key="rendering" className="space-y-3">

And in the SearchableSetting:

           description={
-            contrastEntry?.description ??
             translate(
               'auto.components.settings.TerminalPane.minimumContrastRatio.description',
               'Raises low-contrast ANSI text toward the background until this ratio is met. Set to 1 to use theme colors as-is.'
             )
           }
-          keywords={
-            contrastEntry?.keywords ?? [
-              'terminal',
-              'contrast',
-              'color',
-              'ansi',
-              'minimum contrast',
-              'colors',
-              'xterm'
-            ]
-          }
+          keywords={[
+            'terminal',
+            'contrast',
+            'color',
+            'ansi',
+            'minimum contrast',
+            'colors',
+            'xterm'
+          ]}

Based on learnings, keywords arrays in SearchableSetting should intentionally remain untranslated/English for consistency with other panes.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fc09c0dd-ecd8-4aa7-ad05-5472479a27a5

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb3036 and 183404969e3fde3ef190984a275e77933632fdd3.

📒 Files selected for processing (12)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/renderer/src/components/settings/TerminalRenderingSection.tsx
  • src/renderer/src/components/settings/TerminalSettingsPreview.tsx
  • src/renderer/src/components/settings/setting-labels.ts
  • src/renderer/src/components/settings/terminal-typography-search.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-options.ts
  • src/shared/constants.ts
  • src/shared/types.ts

@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Resolved merge conflict with main (#8050 line-height normalize). Kept main's terminalLineHeight normalization and re-applied minimumContrastRatio on the settings preview. Head: 362fdeecb.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review current head 3f66cdd after the exact-head CI discovered and fixed a stale full-module mock in TerminalSettingsPreview.lifecycle.test.tsx.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@bbingz Got it — kicking off a review of the current head 3f66cddad, including the fix to the stale full-module mock in TerminalSettingsPreview.lifecycle.test.tsx.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz
bbingz force-pushed the fix/7934-minimum-contrast-ratio branch from 3f66cdd to f40ff75 Compare July 14, 2026 00:22
bbingz and others added 3 commits July 14, 2026 08:37
xterm's minimumContrastRatio default of 4.5 can rewrite theme ANSI colors.
Expose Settings → Terminal → Rendering control (1–21, default 4.5) so users
can set 1 for true theme colors while keeping the accessibility default.

Fixes stablyai#7934
@bbingz
bbingz force-pushed the fix/7934-minimum-contrast-ratio branch from f40ff75 to b790abd Compare July 14, 2026 00:37
@AmethystLiang

Copy link
Copy Markdown
Contributor

reviewing

@AmethystLiang
AmethystLiang requested review from AmethystLiang and removed request for Jinwoo-H July 20, 2026 03:18
@AmethystLiang

Copy link
Copy Markdown
Contributor

Thanks a lot for this, @bbingz — the analysis in the summary is spot on, and the configurable implementation is clean.

After thinking it through, we're going to go a slightly different direction: instead of a user setting, gate the contrast enforcement by theme mode automatically — keep 4.5 on light themes (where it was added, to rescue invisible white-on-white ANSI text) and disable it on dark themes, where it was distorting the vibrant colors. The idea is that this just becomes a nicer default with no knob to discover or tune.

Because of that, I'm going to close this in favor of a new PR that takes the theme-gated approach — coming soon, will link it here. Really appreciate the work and the write-up; it directly shaped the decision.

@bbingz

bbingz commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thoughtful follow-up! That direction makes sense to me: keeping 4.5 for light themes while disabling contrast enforcement for dark themes addresses both the original visibility issue and color fidelity without adding another setting. I am glad the analysis and implementation helped shape the decision. Looking forward to the follow-up PR, and happy to help review or test it.

@AmethystLiang

Copy link
Copy Markdown
Contributor

The theme-gated replacement is now open: #9599. As mentioned above, it keeps 4.5 on light themes and disables contrast correction on dark themes automatically, rather than adding a user setting. Thanks again @bbingz — your write-up directly shaped the approach. Closing this in favor of #9599.

AmethystLiang added a commit that referenced this pull request Jul 21, 2026
…luminance (#7934) (#9599)

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

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]>

* 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 (#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]>
@bbingz
bbingz deleted the fix/7934-minimum-contrast-ratio branch August 1, 2026 00:47
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]>
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

3 participants