Skip to content

fix(opencode): incorrect light mode detection in terminals that misreport CSI mode 997#23564

Open
GuillenSanti wants to merge 1 commit intoanomalyco:devfrom
GuillenSanti:fix/ghostty-theme-detection
Open

fix(opencode): incorrect light mode detection in terminals that misreport CSI mode 997#23564
GuillenSanti wants to merge 1 commit intoanomalyco:devfrom
GuillenSanti:fix/ghostty-theme-detection

Conversation

@GuillenSanti
Copy link
Copy Markdown

@GuillenSanti GuillenSanti commented Apr 20, 2026

Issue for this PR

Closes #20926

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Ghostty (and potentially other terminals) responds to CSI mode 997 with "light" even when the actual terminal background is dark (#000000). Since @opentui/core gives CSI priority over OSC, the correct background color inference is discarded and OpenCode renders in light mode.

I traced the issue by logging the renderer internals after waitForThemeMode resolves:

source=csi, oscBg=#000000, oscFg=#f8f8f2

CSI says "light" but the real background is black — a clear contradiction. This happens even with window-theme = dark explicitly set in the Ghostty config, so it's not a user misconfiguration.

The fix adds a resolveThemeMode() function that cross-checks the CSI result against the actual OSC 10/11 background luminance (using the same weighted brightness formula as @opentui/core). When they disagree, the objective color measurement wins.

The function is a no-op when:

  • Detection source wasn't CSI (no override needed)
  • No OSC background color available (can't cross-check)
  • CSI and OSC agree (no contradiction)

How did you verify your code works?

  1. Ran bun run dev in Ghostty with background=#000000 → correctly renders in dark mode (was light before)
  2. Changed Ghostty config to background=#ffffff → correctly renders in light mode (not forced dark)
  3. bun typecheck passes across all packages

Screenshots / recordings

N/A — terminal-only change, behavior verified interactively.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…eport CSI mode 997 by cross-checking against the actual OSC background color luminance
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix incorrect light mode detection in terminals that misreport CSI mode 997 doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 20, 2026
@GuillenSanti GuillenSanti changed the title Fix incorrect light mode detection in terminals that misreport CSI mode 997 fix(opencode): incorrect light mode detection in terminals that misreport CSI mode 997 Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@GuillenSanti GuillenSanti marked this pull request as ready for review April 20, 2026 14:25
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.

no longer respects system theme (macos ghostty)

1 participant