Skip to content

fix(opencode): remove double normalization in terminal background detection#22616

Open
lucoffe wants to merge 1 commit intoanomalyco:devfrom
lucoffe:fix/terminal-background-double-normalization
Open

fix(opencode): remove double normalization in terminal background detection#22616
lucoffe wants to merge 1 commit intoanomalyco:devfrom
lucoffe:fix/terminal-background-double-normalization

Conversation

@lucoffe
Copy link
Copy Markdown

@lucoffe lucoffe commented Apr 15, 2026

Issue for this PR

Closes #22615

Type of change

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

What does this PR do?

RGBA.fromInts() normalizes r/g/b to the 0.0–1.0 range internally. The mode() helper in terminal.ts divides by 255 on top of that — a leftover from the pre-#22297 code where the values were raw 0–255 integers. This double division caps max luminance at ~0.004 (for pure white), so getTerminalBackgroundColor() always returns "dark".

The fix removes the / 255. Related: #20926 (the inverse bug — stuck on light — that #22297 was trying to fix).

How did you verify your code works?

Read the RGBA source in @opentui/core and confirmed fromInts divides by 255 and the .r/.g/.b getters return 0.0–1.0 floats. With the / 255 removed, the luminance formula produces values in the correct 0.0–1.0 range and the 0.5 threshold works as intended.

Screenshots / recordings

N/A — terminal color detection, no UI change.

Checklist

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

RGBA.fromInts() already normalizes r/g/b to 0.0-1.0 range, so dividing
by 255 again in mode() made the luminance near-zero for any input.
This caused getTerminalBackgroundColor() to always return "dark",
breaking light variant selection for all dual-variant themes.

Fixes anomalyco#22615
Related: anomalyco#20926
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@lucoffe lucoffe changed the title fix: remove double normalization in terminal background detection fix(opencode): remove double normalization in terminal background detection Apr 15, 2026
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.

getTerminalBackgroundColor() always returns "dark" due to double color normalization

1 participant