Skip to content

feat(terminal): make the contrast floor user-configurable (#10754) - #10760

Closed
Nanako0129 wants to merge 1 commit into
stablyai:mainfrom
Nanako0129:fix/terminal-configurable-contrast-floor
Closed

Nanako0129 wants to merge 1 commit into
stablyai:mainfrom
Nanako0129:fix/terminal-configurable-contrast-floor

Conversation

@Nanako0129

@Nanako0129 Nanako0129 commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10754.

Summary

Adds an optional terminalMinimumContrastRatio preference 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

  • Extends GlobalSettings with an optional, backward-compatible field.
  • Centralizes bounds and fallback behavior in resolveTerminalMinimumContrastRatio.
  • Value-gates live xterm writes so unrelated settings changes do not clear the contrast cache.
  • Extends the existing NumberField control with an optional reset path and an Automatic placeholder.
  • Adds settings search metadata and English catalog entries using current localization conventions.
  • Adds focused unit coverage plus an Electron E2E that drives a live PTY, changes the floor from 1 → 21 → 1, and verifies the existing buffer visibly repaints and restores.

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

Minimum contrast 21

Contrast correction disabled at 1 (program colors preserved)

Minimum contrast 1

The backing store reported 21 and 1 after the UI commits. Clearing the field then reported no stored value and restored the blank Automatic state.

Testing

  • pnpm run typecheck
  • pnpm run lint
  • Focused Vitest: 7 files, 82 tests passed
  • Electron E2E: terminal-minimum-contrast-setting.spec.ts passed on the final rebased commit
  • Real macOS Orca Electron/CDP validation on an isolated profile: 21 and 1 visibly repainted the terminal preview; clearing restored automatic state
  • Electron development build completed as part of the CDP launch; the E2E bundle also completed
  • Localization catalog and extraction verification (included in pnpm run lint)

An attempted repository-wide pnpm test run 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

  • P0/P1/P2: none found after review and fixes.
  • Security/supply chain: no dependency, lockfile, command execution, path, credential, or new IPC surface. The numeric value is finite-checked and clamped before reaching xterm.
  • Performance/resources: no timers, listeners, subscriptions, or unbounded collections added; live option writes are value-gated.
  • SSH/remoting: renderer-only display preference; it applies to panes regardless of execution host and does not infer process liveness or cross the SSH execution boundary.
  • Mixed-version compatibility: optional local settings field; no RPC params, stream opcodes, or host-published payload changed. Old clients ignore it and new clients retain existing defaults when absent.
  • Cross-platform/provider compatibility: no platform, path, shortcut, shell, Git, GitHub, or GitLab behavior changed. The same renderer path is used on macOS, Linux, Windows, folder workspaces, git worktrees, and remote panes.
  • Mobile-facing assessment: no mobile schema, storage, rendering, or wire surface changed.

Notes

Ghostty's own minimum-contrast setting remains unmapped in the Ghostty importer and is intentionally out of scope.

X: @Nyanako0129

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 30 minutes.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f4553ac5-7762-4d0c-817c-f122933391ef

📥 Commits

Reviewing files that changed from the base of the PR and between 3d74f5f and 2a9e620.

📒 Files selected for processing (15)
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-terminal-options.test.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-options.ts
  • src/renderer/src/components/settings/SettingsFormControls.number-field.test.tsx
  • src/renderer/src/components/settings/SettingsFormControls.tsx
  • src/renderer/src/components/settings/TerminalSettingsPreview.tsx
  • src/renderer/src/components/settings/TerminalWindowSection.tsx
  • src/renderer/src/components/settings/setting-labels.ts
  • src/renderer/src/components/settings/terminal-window-setup-search.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/terminal-contrast-correction.test.ts
  • src/renderer/src/lib/terminal-contrast-correction.ts
  • src/shared/global-settings-types.ts
  • tests/e2e/terminal-minimum-contrast-setting.spec.ts
📝 Walkthrough

Walkthrough

Adds an optional terminal minimum contrast ratio setting with bounded overrides and a value of 1 to disable correction. The setting is exposed in terminal preferences with labels, search metadata, and translations. Terminal previews, dashboard terminals, and pane appearance now apply the configured ratio and respond to changes. Unit tests cover override resolution, clamping, fallback, and opt-out behavior. A Playwright test verifies live repainting and reversibility through pixel comparisons.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 implements #10754's requested configurable minimum contrast setting, override behavior, live updates, and tests.
Out of Scope Changes check ✅ Passed The changes stay focused on terminal contrast settings, related UI/i18n wiring, and test coverage with no clear unrelated additions.
Title check ✅ Passed The title is concise and clearly describes the main change: making the terminal contrast floor configurable.
Description check ✅ Passed The description matches the required template with Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes filled in.

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 (2)
src/renderer/src/lib/terminal-contrast-correction.test.ts (1)

76-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Trailing assertions in the opt-out test are tautological.

Since resolveTerminalMinimumContrastRatio(..., 1) always returns MIN_CONTRAST_RATIO (1), and any WCAG contrast ratio computed by contrastRatio() is mathematically always >= 1, expect(seam).toBeGreaterThanOrEqual(optedOut) (and the secondaryText counterpart) 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 value

Duplicate active-pane resolution logic.

readTerminalScreenBox (lines 42-62) and readAppliedContrastRatio (lines 67-79) both re-implement the same tab-id → pane-manager → active-pane lookup inline in page.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.tsx
  • src/renderer/src/components/settings/TerminalSettingsPreview.tsx
  • src/renderer/src/components/settings/TerminalWindowSection.tsx
  • src/renderer/src/components/settings/setting-labels.ts
  • src/renderer/src/components/settings/terminal-window-setup-search.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/terminal-contrast-correction.test.ts
  • src/renderer/src/lib/terminal-contrast-correction.ts
  • src/shared/types.ts
  • tests/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.
@nwparker
nwparker force-pushed the fix/terminal-configurable-contrast-floor branch from 7932b3f to 2a9e620 Compare August 23, 2026 23:32
@nwparker
nwparker requested a review from brennanb2025 as a code owner August 23, 2026 23:32
@nwparker

Copy link
Copy Markdown
Contributor

Readiness verdict

Code-ready; GitHub merge is blocked only by maintainer approval of the fork workflows. Final head: 2a9e62030a9f1cf3337e8e0186e16ee649474cc7, cleanly rebased on current origin/main and force-pushed with an exact lease.

Findings

  • P0: none
  • P1: none
  • P2: none remaining

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 Automatic. Dashboard preview writes are also value-gated so unrelated settings changes do not unnecessarily clear xterm's contrast cache.

Tests by machine

macOS local (Apple Silicon)

  • pnpm run typecheck — passed on the final rebased commit
  • pnpm run lint — passed, including code-quality ratchets and localization catalog/extraction checks
  • Focused Vitest — 7 files / 82 tests passed on the final rebased commit
  • Electron E2E terminal-minimum-contrast-setting.spec.ts — passed on the final rebased commit; live PTY render changed at 1 → 21 and restored at 21 → 1
  • Real Orca Electron/CDP with isolated profile — Settings search found the control; UI commits stored 21 and 1; the terminal preview visibly repainted; clearing restored blank Automatic and removed the persisted override
  • Electron dev build and the E2E Electron/renderer/CLI bundle — passed

Repository-wide pnpm test was attempted but stopped after several concurrently running worktree suites caused unrelated timeout/watcher-starvation failures across SSH relay, persistence, source control, sidebar, and orchestration tests. No failure referenced the changed contrast files; the focused renderer suite and live Electron E2E are green.

Visual proof

Both are current, uncropped Electron/CDP screenshots from the final rebased tree.

Compatibility and residual risk

  • No dependency, lockfile, command, path, credential, process, or new IPC/wire surface.
  • Optional local settings field is safe under mixed client/server versions; no RPC params or stream opcodes changed.
  • Renderer-only behavior follows the same path for local, SSH, remote, worktree, and folder-workspace panes; no execution-liveness verdict changed.
  • No platform-specific, mobile-facing, GitHub-only, or GitLab-specific behavior changed.
  • Residual risk is limited to untested manual rendering on Linux/Windows; the path is platform-neutral and covered by unit/Electron tests.
  • Ghostty importer support for Ghostty's own minimum-contrast key remains intentionally out of scope.

Exact merge blockers

GitHub reports the PR as MERGEABLE but UNSTABLE because both new fork workflow runs require maintainer action and have no check runs yet:

No code or conflict blocker remains. A maintainer must approve those workflows and wait for their required checks to complete before merging.

@OrcaWin

OrcaWin commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

@Nanako0129 we merged #18126

@OrcaWin OrcaWin closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The dark-background contrast floor is not configurable, and it rewrites Powerline statusline colors

3 participants