fix: improve text contrast on light terminal backgrounds#712
fix: improve text contrast on light terminal backgrounds#712altimate-harness-bot[bot] wants to merge 6 commits intomainfrom
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
- Add COLORFGBG env var fallback when OSC 11 detection times out - Use dark foreground (#1a1a1a) instead of palette[7] (#c0c0c0) for light mode system theme - Use backgroundElement for inline code blocks to ensure contrast on transparent backgrounds Closes #704
- Test markup.raw.inline uses backgroundElement (non-transparent) - Test system theme light-mode foreground fallback contrast - Test COLORFGBG env var parsing logic - Update test helper to match production inline code background change
72d8b51 to
d3a4dac
Compare
Adds tests that reproduce the exact bugs: - BUG test: proves palette[7] (#c0c0c0) has ~1.3:1 contrast on white (invisible) - BUG test: proves old inline code bg was transparent (no contrast) - FIX test: verifies new fg (#1a1a1a) has >=3:1 contrast on white - FIX test: verifies inline code bg is now opaque - FIX test: verifies dark mode is unaffected (still uses palette[7])
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
…tion Addresses the multi-model consensus code review on PR #712. **COLORFGBG detection**: - Extract `detectModeFromCOLORFGBG` into a pure TypeScript helper at `packages/opencode/src/cli/cmd/tui/util/terminal-detection.ts` so tests exercise the real production code (was previously inlined in `app.tsx` with test duplicates that couldn't catch regressions). - Narrow the light-mode threshold from `bg >= 8` to `bg === 7 || bg === 15`. The old `>= 8` misclassified bright red (9), blue (12), magenta (13) as "light" even though they have low luminance; it also missed index 7 (light gray), which is a common light-terminal background. - Reject out-of-range (< 0, > 15), non-numeric ("default"), and empty values explicitly rather than silently defaulting to dark. - Tolerate surrounding whitespace. - Use `parseInt(..., 10)` with an explicit radix. - Check `COLORFGBG` eagerly in `getTerminalBackgroundColor()` before issuing the OSC 11 query. Light terminals that don't support OSC 11 (common with urxvt, gnome-terminal) no longer pay the 1-second timeout on every launch. **System-theme light-mode foreground fallback**: - `generateSystem` now falls back to `colors.palette[0] ?? "#1a1a1a"` in light mode (dark mode keeps `colors.palette[7]`). Respects the user's palette when provided; still guarantees a readable near-black on white when the palette is empty. **Tests**: - Rewrite `theme-light-mode-704.test.ts` to import the real `detectModeFromCOLORFGBG` — reverting the production helper now fails the 18 COLORFGBG tests. - Add coverage for: `0;7` (light-gray bg, now light), `15;8` (dark-gray bg, now dark), `0;9`/`0;12`/`0;13` (bright-red/blue/magenta, now dark), `default;default` (Alacritty/Kitty), out-of-range values, negatives, empty string, whitespace tolerance, undefined. - Add a light-mode regression test confirming fallback prefers `palette[0]` over `#1a1a1a` when present. - Add `defaultForeground`-is-honored regression. - Add dark-mode `markup.raw.inline` regression test in `theme-light-mode.test.ts` to cover the cross-mode impact of the `backgroundElement` change. - Consolidate duplicate `COLORFGBG` tests (previously in both files). Closes #704 (follow-up to #712/#617).
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
|
Ran multi-model consensus review (9 participants: Claude + GPT 5.4, Gemini 3.1 Pro, Kimi K2.5, DeepSeek V3.2, MiniMax M2.7, GLM-5, MiMo-V2-Pro, Qwen 3.5 Plus). One convergence round. Summary below, followed by the fixes just pushed (commit 8f747a1). Review findingsMajor blocker (unanimous): Tests duplicated production logic ( Minor — COLORFGBG threshold:
Minor — Minor — 1000ms startup delay: COLORFGBG was only consulted after the OSC 11 timeout. Terminals without OSC 11 (urxvt, older gnome-terminal) paid 1s on every launch. Minor — Missing dark-mode regression for Fixes applied in commit 8f747a1
Full test suite: 59 pass, 0 fail. Test architecture note: the theme-level tests still use local helpers because |
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
|
👋 This PR was automatically closed by our quality checks. Common reasons:
If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you. |
Summary
Fixes #704 (follow-up to #617). Code output was rendering as white/light text on light terminal backgrounds, making it unreadable.
Three fixes:
COLORFGBG env var fallback (
app.tsx): When OSC 11 terminal background detection times out (common in many terminal setups), fall back to checking theCOLORFGBGenvironment variable before defaulting to "dark" mode. Many terminals (iTerm2, xterm, etc.) set this to indicate their color scheme.Light-mode foreground fallback (
theme.tsx): WhendefaultForegroundis unavailable and mode is "light", use#1a1a1a(near-black) instead of ANSI palette index 7 (#c0c0c0— light gray), which is invisible on white backgrounds.Inline code background (
theme.tsx): UsebackgroundElementinstead ofbackgroundformarkup.raw.inlinescope.backgroundcan be transparent (especially in the system theme), leaving inline code with no contrast protection. This is consistent with the Asking the model to do a suggestion for rewrite of code during review returns white lines of code while terminal background is white #617 fix already applied tomarkup.raw.block.Test plan
COLORFGBGenv varRequested by @saravmajestic via harness
Summary by cubic
Fixes unreadable code on light terminal backgrounds with better detection and safer color fallbacks. Also removes the 1s startup delay on terminals without OSC 11; inline code now always has a solid background. Closes #704.
COLORFGBGviadetectModeFromCOLORFGBG(util/terminal-detection.ts); only bg 7/15 count as light; reject invalid values; run this check before OSC 11 to avoid delays.#1a1a1ainstead of palette[7]; dark mode unchanged.markup.raw.inline) now usesbackgroundElementto ensure contrast on transparent themes.Written for commit 8f747a1. Summary will update on new commits.