Skip to content

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

Merged
OrcaWin merged 3 commits into
mainfrom
nwparker/bug-the-dark-background-contrast-floor-is-not-co
Sep 8, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
nwparker/bug-the-dark-background-contrast-floor-is-not-co

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10754. Based on @Nanako0129’s #10760; their co-author credit is retained.

Change

Orca’s automatic contrast correction brightens intentionally dim TUI text and Powerline styling. Settings → Terminal → Rendering → Color Contrast now offers three plain-language choices:

Choice Behavior
Automatic Recommended default. Keeps the existing background-based correction: 3 dark / 4.5 light.
Off Preserves program colors, including dim text and Powerline separators. No numeric input needed.
Custom Reveals a Subtle → Strong slider and an optional precise contrast target. Starts at 4.5.

Returning to Automatic removes the stored override in one click. Custom remembers its previous target while switching modes within the mounted settings control. Slider changes save on commit; arrow keys adjust the target. Exact input is bounded to 1–21, and entering 1 selects Off. The slider starts at 1.1 so reaching its lower end does not collapse the Custom controls.

The underlying optional terminalMinimumContrastRatio remains compatible: absent = Automatic, 1 = Off, other valid numbers = Custom. No new setting or wire field is introduced by this UX revision.

Settings screenshots — current UI

Fresh hidden Electron/CDP captures from the implementation in c997d35f96. These replace the earlier blank-input screenshots. They show the full settings page and surrounding options, with no settings search filter unless explicitly labeled.

Automatic — a recommended default, with no number to manage.

Automatic contrast mode

Off — preserve the colors chosen by the program in one click.

Off preserves program colors

Custom — progressively reveals a slider and precise value field.

Custom contrast with slider and exact target

More settings proof: custom values, bounds, light mode, search, and narrow layout

Custom target 7 — also verified to survive Off → Automatic → Custom.

Custom target 7

Entering 99 clamps to 21.

Custom target clamped to 21

Light mode, Automatic.

Automatic contrast in light mode

Light mode, Custom.

Custom contrast in light mode

Search for “powerline” finds the control.

Powerline settings search

Narrower window, Custom.

Custom contrast in a narrower window

Terminal rendering proof

The renderer behavior is unchanged by the UX revision. These existing captures used the same live PTY and terminal instance in a folder workspace, with the original issue’s ANSI foreground/background samples. “Auto” and “1” in the earlier measurements map to today’s Automatic and Off choices.

Automatic: the seam sample becomes readable and deliberately dim text is brightened.

Automatic terminal rendering

Off: the seam sample becomes nearly invisible and secondary text stays dim.

Off terminal rendering

Earlier live-buffer measurement Changed pixels versus Automatic in the identical 1530 × 780 crop
Off (1) 16,383
Custom 4.5 16,245
Custom 21 16,822
Restore Automatic 0 — pixel-identical restoration

The 520 × 22 sample spanning all seven background swatches had 0 changed pixels in every dark-mode state. Terminal identity and buffer text were preserved. These measurements establish foreground correction, not a palette/background change; they were captured before the new mode control.

Light theme and background-based defaults — 3 screenshots

The floor follows the composed terminal background, not the app’s light/dark mode. The capture script reads 4.5 for both light-background Auto cases and 1 for the disabled case.

Light terminal background: automatic ratio is 4.5

Light terminal background: automatic ratio is 4.5

Light terminal background: 1 disables correction here too

Light terminal background: 1 disables correction here too

Light theme in the dark theme slot: full app context

Light theme in the dark theme slot: full app context

Appearance preview — 2 screenshots

Both values were entered in the Terminal setting before navigating to Appearance. The preview uses the same resolver as live panes.

Appearance preview with the target set to 21

Appearance preview with the target set to 21

Appearance preview with correction disabled at 1

Appearance preview with correction disabled at 1

Mobile document rendering — 2 screenshots; not a phone test

The complete generated mobile WebView HTML was loaded in an iframe inside the hidden Electron renderer, initialized through its actual message handler, and updated with a set-theme message. It rendered the same ANSI sample with no captured engine/runtime errors. This exercises the document and its bundled xterm, not React Native pairing, an iPhone, or an Android device.

Mobile WebView document: Auto

Mobile WebView document: Auto

Mobile WebView document: published override 1

Mobile WebView document: published override 1

Full desktop context — 2 uncropped screenshots

Full Orca window: Auto

Full Orca window: Auto

Full Orca window: correction off

Full Orca window: correction off

Review map and comparison with #10760

  • Same core feature: preserve existing defaults, allow correction to be disabled, clamp valid overrides, and feed the pane plus both desktop previews through the shared resolver.
  • This PR adds: desktop persistence normalization and an optional mobile theme override with a safe fallback. The new UX presents Automatic / Off / Custom instead of exposing JSON conventions to users.
  • Contributor PR adds: a committed pixel E2E (terminal-minimum-contrast-setting.spec.ts) and an explicit value-gated dashboard appearance helper. The E2E is not ported here; this PR’s dashboard constructor reads the override when the existing settings/theme effect reruns.
  • Credit: @Nanako0129 authored both the issue and feat(terminal): make the contrast floor user-configurable (#10754) #10760 and is a recognized co-author on the original implementation commit.

Start with TerminalContrastSetting.tsx for mode selection and custom tuning, then terminal-minimum-contrast-settings.ts and terminal-contrast-correction.ts for numeric validation/defaults. Desktop consumers are terminal-appearance.ts, TerminalSettingsPreview.tsx, and preview-terminal-options.ts. Mobile publication and reading live in mobile-terminal-theme.ts and terminal-webview-theme-injected.ts.

Verification

Current UX revision:

  • ORCA_BACKGROUND_LAUNCH=1 pnpm tc:web — passed.
  • Focused mode-control, NumberField, and resolver tests — 3 files / 21 tests passed. Mode tests cover one-click Off/Automatic, custom-value memory, default custom target, bounds, and exact input 1 selecting Off.
  • Real hidden Electron/CDP: Automatic and Off hide numeric controls; Custom reveals them; ArrowRight changes 4.5 → 4.6; exact 7 persists and survives mode changes; 99 clamps to 21; Automatic removes the override. Dark/light, narrow layout, and settings search captured above.
  • Changed-file lint, React Doctor commit hook, formatting, localization extraction, and git diff --check — passed.

Rebased rendering implementation: full pnpm tc, 65 focused desktop tests, and 21 focused mobile tests passed on ee33b92964, rebased onto main at c1e15c4008. Earlier actual-source mobile VM validation covered 18 dark/light/invalid/clamp cases. The complete mobile document also rendered without captured engine errors in an Electron iframe (screenshots above); this is not phone/pairing validation.

The earlier mobile payload checksum CI failure was reproduced and fixed by updating the expected document length/hash after validating the intentional injected-JS change. CI must pass on the latest head before merge.

Compatibility and limits

  • Automatic preserves existing defaults and the pane’s value-gated option write. Invalid/non-finite overrides fall back safely.
  • This is a client display preference: desktop IPC reaches persistence normalization; web preferences merge locally and are validated by the renderer resolver. It is not sent through the restricted host settings.update RPC.
  • Mobile’s optional theme field is ignored by older clients; newer clients fall back to the background gate when older publishers omit it. No new opcode or required field.
  • No execution, process-liveness, shell, Git, or provider behavior changes. SSH and folder/worktree panes use the same renderer preference. Actual remote pairing, Linux/Windows rendering, and physical phones were not exercised here.
  • Ghostty minimum-contrast import remains out of scope.

New screenshots are GitHub attachments uploaded using gh pr edit --attach (CLI 2.100.0). The terminal and mobile galleries retain their earlier capture provenance; obsolete settings screenshots have been removed from this description.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

Adds an optional terminalMinimumContrastRatio setting with shared bounds and normalization. Persists normalized values and applies them to desktop terminals and previews. Adds a clearable NumberField and localized settings UI. Publishes normalized ratios through the mobile runtime theme and applies valid overrides in the mobile terminal WebView. Adds tests for persistence, resolution, UI behavior, mobile synchronization, and fallback handling.

Priority: ➖ Normal — Impact reflects medium issue severity.

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to c997d

Terminal contrast now supports automatic, off, and custom targets across clients. Entering Off through the precise custom input can lose the user’s previous target, and the setting label localization concern remains open; both should be addressed before release.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 24 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: making the terminal contrast floor user-configurable.
Description check ✅ Passed The description is detailed and covers the change, rationale, linked issue, visual proof, testing, compatibility, and scope. It does not use every template heading, including ELI5, Why, Review, and Ch…
Linked Issues check ✅ Passed The changes address issue #10754 by preserving automatic contrast floors, adding a configurable terminal minimum contrast setting, supporting 1 to disable correction, clamping valid values, preserving…
Out of Scope Changes check ✅ Passed The changes remain related to the linked issue. The settings UI, shared normalization, persistence, desktop consumers, mobile propagation, localization, and tests support the configurable terminal con…
Full details: Docstring Coverage

Explanation

Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 24 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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: Team

Run ID: 38ed32e0-e6f9-4a0b-988b-08154e719935

📥 Commits

Reviewing files that changed from the base of the PR and between 8197268 and d3795a3.

📒 Files selected for processing (22)
  • mobile/src/terminal/terminal-webview-theme-injected.test.ts
  • mobile/src/terminal/terminal-webview-theme-injected.ts
  • src/main/persistence/applying-settings/settings-update-terminal-contrast.test.ts
  • src/main/persistence/applying-settings/settings-update.ts
  • 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/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.test.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/renderer/src/runtime/sync-runtime-graph/mobile-terminal-theme.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/mobile-terminal-theme.ts
  • src/shared/global-settings-types.ts
  • src/shared/runtime-mobile-session-tab-contracts.ts
  • src/shared/terminal-minimum-contrast-settings.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

terminalFastScrollSensitivity: 'Fast Scroll Speed',
terminalTuiScrollSensitivity: 'TUI Scroll Speed',
terminalBackgroundOpacity: 'Background Opacity',
terminalMinimumContrastRatio: 'Minimum Contrast Ratio',

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Localize the new setting label.

SETTING_LABELS adds a hard-coded English label. Use the existing intent-named minimumContrast.title translation key so this label follows the active locale.

Based on learnings: newly added user-facing strings in renderer settings code must use intent-named localization IDs.

Source: Learnings

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • User-configurable contrast floor — new optional terminalMinimumContrastRatio setting; undefined keeps the automatic background-luminance floor (4.5 light / 3 dark), 1 disables correction, other values pin the floor, all clamped to xterm's [1, 21] via shared normalizeTerminalMinimumContrastRatio.
  • Resolver override — resolveTerminalMinimumContrastRatio gains an override argument that wins over the luminance gate; all three consumers (live panes, dashboard preview, settings preview) now pass it.
  • Persistence-boundary clamp — settings-update.ts normalizes the field on write so desktop IPC, web RPC, and the CLI can't hand xterm an out-of-range or non-finite floor; a hand-edited profile stays clamped by the resolver too.
  • Settings UI — NumberField gains opt-in onClear/placeholder, and a new Terminal → Rendering row with dynamic helper text plus search keywords/catalog entry.
  • Mobile parity — the resolved floor is published as a new optional field on RuntimeMobileTerminalTheme; the injected webview prefers it and falls back to the luminance gate when absent, so old hosts/clients stay compatible without negotiation.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Refreshed the mobile payload checksum fixture — updated EXPECTED_LENGTH / EXPECTED_SHA256 in terminal-webview-payload-hash.test.ts to match the emitted WebView document, resolving the failed mobile verify CI job.
  • Clarified the pinned-ratio helper copy — the pinned string now reads "Targets {{ratio}}:1 contrast for foreground colors, where possible." instead of "Foreground colors are lifted until they reach …", removing the overpromise for backgrounds where the target is unachievable. The fallback in TerminalRenderingSection.tsx and en.json stay in sync.

Both changes are fixtures/copy only — no resolver, settings, persistence, or mobile-injection logic changed since the prior review.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

nwparker and others added 2 commits September 7, 2026 19:09
The xterm minimumContrastRatio floor was hardcoded (3 on dark backgrounds,
4.5 on light) and applied to every pane with no way out, so TUIs that use
deliberately low contrast were rewritten: Powerline separators drawn in the
neighbouring segment's background became visible seams, and dimmed secondary
text lost its hierarchy.

Adds an optional `terminalMinimumContrastRatio` setting under Settings ->
Terminal -> Rendering. Blank keeps today's automatic, background-luminance
gated floor; 1 disables correction entirely (matching VS Code's documented
`terminal.integrated.minimumContrastRatio` and iTerm2's off-by-default
Minimum Contrast); values are clamped to xterm's 1-21 range.

The floor is resolved in one place, so live panes, the Appearance preview
and the dashboard terminal preview all follow it, and the existing
value-gated write still avoids clearing xterm's contrast cache on no-op
re-applies. The clamp also lives at the persistence boundary that every
writer crosses, so a hand-edited profile or CLI write can never hand xterm
a non-finite option. Mobile mirrors the desktop gate, so the resolved floor
travels with the terminal theme payload as a new optional field; hosts that
omit it leave older and newer clients on the luminance gate.

Fixes #10754.

Co-authored-by: Nyanako <[email protected]>
@OrcaWin
OrcaWin force-pushed the nwparker/bug-the-dark-background-contrast-floor-is-not-co branch from c82bde5 to ee33b92 Compare September 8, 2026 02:11
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Rebased onto main (c1e15c4008) — the previously reported merge conflicts are resolved. History was consolidated to 3fcd2101d2 (feature) + ee33b92964 (fixture/copy), and the PR's own files are byte-identical to the prior-reviewed head c82bde5: resolver override, settings UI, persistence clamp, and mobile publication are all unchanged.
  • No new behavioral surface — the shared type/component files (global-settings-types.ts, runtime-mobile-session-tab-contracts.ts, SettingsFormControls.tsx, terminal-appearance.ts) only picked up unrelated main drift (cursor-blink suspension, MiniMax region, className passthrough), none of which alters the contrast-floor logic.

No inline comments this pass. CI should be allowed to run against the rebased head before merge.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@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: Advanced

Run ID: 9b047cb9-296c-4961-8fe9-af0b86676a0a

📥 Commits

Reviewing files that changed from the base of the PR and between ee33b92 and c997d35.

📒 Files selected for processing (6)
  • src/renderer/src/components/settings/TerminalContrastSetting.test.tsx
  • src/renderer/src/components/settings/TerminalContrastSetting.tsx
  • src/renderer/src/components/settings/TerminalRenderingSection.tsx
  • src/renderer/src/components/settings/setting-labels.ts
  • src/renderer/src/components/settings/terminal-typography-search.ts
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/settings/setting-labels.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/components/settings/terminal-typography-search.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

max={MAX_TERMINAL_CONTRAST_RATIO}
step={0.1}
suffix=":1"
onChange={(ratio) => updateSettings({ terminalMinimumContrastRatio: ratio })}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve the custom target when precise input selects Off.

When a user enters 1, save the preceding custom target before writing the Off sentinel. Line 117 bypasses selectMode, so lastCustomValue remains at its initial fallback. A stored target of 7 then restores as 4.5 after the user selects Custom again.

Add a regression case that enters 1 from custom mode and verifies that Custom restores the prior target in src/renderer/src/components/settings/TerminalContrastSetting.test.tsx.

@OrcaWin
OrcaWin merged commit 53852c9 into main Sep 8, 2026
4 of 22 checks passed
nwparker added a commit that referenced this pull request Sep 8, 2026
…e main static analysis

The 7 auto.components.settings.TerminalPane.minimumContrast.* entries added by #18126 have zero call sites; the shipped component reads settings.contrast.*. Because the runtime-required catalog classifies any key with no literal-default call site as required, the orphans broke 'Verify runtime-required localization catalog' on main and red-lit every PR in the repo.

Deleting them is the root-cause fix: regenerating would instead add dead strings to the boot bundle. On main+delete, --fix regenerates a byte-identical catalog and the CI step exits 0.

Merged with 'test / tests node 24 3/8' red: that failure is an unrelated main break from the #19542/#19551 collision, not from this change.
williamfligor added a commit to williamfligor/orca that referenced this pull request Sep 11, 2026
The contrast floor is user-configurable upstream (stablyai#18126) and the POSIX
query-reply ordering fix shipped as stablyai#15559/stablyai#15578, so neither needs
tracking anymore.
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.

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

2 participants