Repository navigation
feat(terminal): make the contrast floor user-configurable (#10754) - #10760
Nanako0129 wants to merge 1 commit into
Conversation
|
Warning Review limit reachedNext included review available in 30 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
📝 WalkthroughWalkthroughAdds an optional terminal minimum contrast ratio setting with bounded overrides and a value of 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/renderer/src/lib/terminal-contrast-correction.test.ts (1)
76-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTrailing assertions in the opt-out test are tautological.
Since
resolveTerminalMinimumContrastRatio(..., 1)always returnsMIN_CONTRAST_RATIO(1), and any WCAG contrast ratio computed bycontrastRatio()is mathematically always>= 1,expect(seam).toBeGreaterThanOrEqual(optedOut)(and thesecondaryTextcounterpart) can never fail — they don't actually verify the opt-out behavior beyond what line 50 already covers.Consider replacing with an assertion that the seam/secondaryText values are unchanged relative to a corrected baseline (e.g. comparing against
resolveTerminalMinimumContrastRatio(DARK_BG, 'dark')isn't testing the colors themselves, only the floor value), or dropping the redundant checks.tests/e2e/terminal-minimum-contrast-setting.spec.ts (1)
41-80: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate active-pane resolution logic.
readTerminalScreenBox(lines 42-62) andreadAppliedContrastRatio(lines 67-79) both re-implement the same tab-id → pane-manager → active-pane lookup inline inpage.evaluate. Extracting a shared helper (e.g.resolveActivePane(page)) would remove the duplication.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8654b710-0a9f-40f4-92d7-c366d67eb5c7
📥 Commits
Reviewing files that changed from the base of the PR and between 8f5a454 and 7932b3ff83c0d29b5384865f752702cf0f5391ac.
📒 Files selected for processing (15)
src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsxsrc/renderer/src/components/settings/TerminalSettingsPreview.tsxsrc/renderer/src/components/settings/TerminalWindowSection.tsxsrc/renderer/src/components/settings/setting-labels.tssrc/renderer/src/components/settings/terminal-window-setup-search.tssrc/renderer/src/components/terminal-pane/terminal-appearance.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/lib/terminal-contrast-correction.test.tssrc/renderer/src/lib/terminal-contrast-correction.tssrc/shared/types.tstests/e2e/terminal-minimum-contrast-setting.spec.ts
…0754) xterm's minimumContrastRatio was pinned to the luminance-gated defaults (3 on a dark background, 4.5 on a light one) and written unconditionally to every pane, with no setting to change or disable it. For a TUI that picks low-contrast colors on purpose the correction rewrites its output: a Powerline statusline draws the seam between two segments in the neighbouring segment's background color (xterm 238 on 237, 1.17:1) so the join is invisible by design, and dims secondary text (245 on 238, 2.82:1) to keep a hierarchy against the primary text. Both sit under the dark floor, so every pill seam became a visible bright line and the hierarchy flattened. Adds an optional GlobalSettings.terminalMinimumContrastRatio. resolveTerminalMinimumContrastRatio now takes a third override argument and, when it is a finite number, clamps it to 1..21 (xterm treats 1 as "never correct"; 21 is the largest ratio that exists, black on white) and returns it in place of the luminance-gated default. An absent or non-finite override keeps the existing behaviour untouched, so nothing changes for anyone who does not set it. The bound is exported as MIN_CONTRAST_RATIO / MAX_CONTRAST_RATIO so the settings control and the resolver cannot drift apart. All three call sites that own a live xterm now pass the override: applyTerminalAppearance for real panes, TerminalSettingsPreview, and AgentTerminalPreview. The first two already re-run on a settings write; AgentTerminalPreview rebuilds its Terminal inside an effect keyed on scalars, so the override is read into a scalar rather than adding the whole settings object to the dependency list, which would rebuild the terminal on every unrelated settings change. TerminalSettingsPreview's theme effect gains the same value as a dependency so the preview cannot show a different floor than live panes. The existing value-gated write in applyTerminalAppearance is unchanged and still avoids clearing xterm's contrast cache on a no-op re-apply; because that write does clear the cache when the value does change, an existing buffer repaints without a reprint or a pane restart. The control is a NumberField in TerminalWindowSection, next to Color Overrides, since it is the last stage of the same color pipeline (overrides, then theme composition, then contrast correction). It is registered in the settings search catalog under contrast / readability / legibility / wcag / color, and in SETTING_LABELS. NumberField cannot represent "unset", so the field shows DARK_BG_MIN_CONTRAST as its displayed default and the description spells out that leaving it alone follows the background (3 dark, 4.5 light) while setting it pins the value. New strings are localized with keys generated by the repository's sha1(filePath + ':' + text) scheme and the catalogs for es, ja, ko and zh were repaired to parity. Unit tests cover the override winning over the default, clamping at both ends, falling back on undefined and NaN, and the reported case: the Powerline seam and dimmed-text ratios are asserted to sit under the default floor and at or above an override of 1. The e2e drives the setting to both ends of its range against a live pane and compares renders rather than asserting an absolute color, because xterm applies the correction in the renderer (the cell's SGR attributes keep reporting the original color) and the painted value is shifted by DPR and color management. Going 1 -> 21 must move more than 500 pixels of the probe, and returning to 1 must restore the original render within 100. Comparing the two ends rather than default-vs-1 keeps the test valid under either terminal theme, since the theme decides the default floor; a diagnostic run confirmed the harness uses a light theme, where this probe's colors do not trip the 4.5 default at all. Not included: Ghostty's own minimum-contrast key is still unmapped in the Ghostty settings importer.
7932b3f to
2a9e620
Compare
Readiness verdictCode-ready; GitHub merge is blocked only by maintainer approval of the fork workflows. Final head: Findings
The review fixed one functional issue before push: the control originally could pin a ratio but could not return to automatic luminance-based behavior. Clearing the field now removes the override and restores Tests by machinemacOS local (Apple Silicon)
Repository-wide Visual proofBoth are current, uncropped Electron/CDP screenshots from the final rebased tree. Compatibility and residual risk
Exact merge blockersGitHub reports the PR as No code or conflict blocker remains. A maintainer must approve those workflows and wait for their required checks to complete before merging. |
|
@Nanako0129 we merged #18126 |
Fixes #10754.
Summary
Adds an optional
terminalMinimumContrastRatiopreference under Settings → Appearance → Terminal → Advanced. Blank keeps Orca's existing automatic floor (3 on dark backgrounds, 4.5 on light backgrounds); values are clamped to 1–21; setting 1 disables xterm contrast correction so TUIs can render deliberately low-contrast colors unchanged.The preference applies live to normal terminal panes, the settings preview, and dashboard terminal previews. Clearing the field removes the override and returns to automatic behavior without restarting a pane.
Implementation
GlobalSettingswith an optional, backward-compatible field.resolveTerminalMinimumContrastRatio.NumberFieldcontrol with an optional reset path and anAutomaticplaceholder.Visual proof (macOS local, final rebased tree)
Both images are uncropped Orca Electron/CDP captures of the same preview and buffer.
Contrast correction forced to 21
Contrast correction disabled at 1 (program colors preserved)
The backing store reported 21 and 1 after the UI commits. Clearing the field then reported no stored value and restored the blank
Automaticstate.Testing
pnpm run typecheckpnpm run lintterminal-minimum-contrast-setting.spec.tspassed on the final rebased commitpnpm run lint)An attempted repository-wide
pnpm testrun was stopped after host-wide contention from several concurrent worktree suites caused unrelated timeout and watcher-starvation failures across SSH relay, persistence, source control, sidebar, and orchestration tests. The focused renderer tests and the live Electron E2E both pass on the final rebased commit.Readiness review
Notes
Ghostty's own
minimum-contrastsetting remains unmapped in the Ghostty importer and is intentionally out of scope.X: @Nyanako0129