[PR #5296] feat(tui): add theme-configurable text selection colors #11329

Closed
opened 2026-02-16 18:16:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5296

State: closed
Merged: No


Summary

Fixes #5295

Add selection and selectionForeground properties to the theme system to fix poor text selection contrast on light terminals.

Problem

When selecting text to copy on light terminals, the default @opentui/core behavior inverts foreground/background colors. This works for dark themes but produces unreadable selections on light themes (dark text → dark selection background with poor contrast).

Solution

  • Add optional selection and selectionForeground properties to the theme schema
  • Provide smart fallbacks when not specified:
    • selection defaults to theme's primary color
    • selectionForeground auto-calculated based on luminance for contrast
  • Pass selection colors to all text-rendering components in the session view

Theme authors can customize these values, but existing themes work without changes due to the fallbacks.

Changes

  • theme.tsx: Add selection color types, schema support, and fallback logic
  • orng.json: Add explicit selection colors as example
  • session/index.tsx: Pass selectionBg/selectionFg props to text components

Screenshots

1.0.137 Unreadable Text Selection:

CleanShot 2025-12-09 at 14 53 16@2x

Examples of PR Solution:

CleanShot 2025-12-09 at 14 41 39@2x CleanShot 2025-12-09 at 14 44 51@2x

Testing

Tested with opencode and orng themes on light terminal (Ghostty) - selection is now clearly visible with high contrast.

CI Failures

The CI failures (format and test) appear to be pre-existing issues unrelated to this PR - the dev branch shows similar intermittent failures. The format failure is related to SDK generation (openapi.ts not found), and the test failure is in tool.patch, neither of which are touched by this PR.

Notes

This solution was developed with assistance from Claude Opus 4.5 and may not be the preferred approach by maintainers. A simpler solution might involve updating the default selection color handling in @opentui/core itself to better handle light terminal scenarios. However, this PR provides a working solution that I'm using in my local build in the interim, and at minimum demonstrates the issue and one viable fix.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5296 **State:** closed **Merged:** No --- ## Summary Fixes #5295 Add `selection` and `selectionForeground` properties to the theme system to fix poor text selection contrast on light terminals. ## Problem When selecting text to copy on light terminals, the default `@opentui/core` behavior inverts foreground/background colors. This works for dark themes but produces unreadable selections on light themes (dark text → dark selection background with poor contrast). ## Solution - Add optional `selection` and `selectionForeground` properties to the theme schema - Provide smart fallbacks when not specified: - `selection` defaults to theme's `primary` color - `selectionForeground` auto-calculated based on luminance for contrast - Pass selection colors to all text-rendering components in the session view Theme authors can customize these values, but existing themes work without changes due to the fallbacks. ## Changes - `theme.tsx`: Add selection color types, schema support, and fallback logic - `orng.json`: Add explicit selection colors as example - `session/index.tsx`: Pass `selectionBg`/`selectionFg` props to text components ## Screenshots ### 1.0.137 Unreadable Text Selection: <img width="3006" height="2495" alt="CleanShot 2025-12-09 at 14 53 16@2x" src="https://github.com/user-attachments/assets/a55cedb2-5cee-458e-b3f2-fb70b0b585c2" /> ### Examples of PR Solution: <img width="3008" height="2495" alt="CleanShot 2025-12-09 at 14 41 39@2x" src="https://github.com/user-attachments/assets/c3ca9da4-4486-4153-a5af-a7245babd249" /> <img width="3009" height="2502" alt="CleanShot 2025-12-09 at 14 44 51@2x" src="https://github.com/user-attachments/assets/7899e0fb-d5fc-4d1f-aa20-b2cb837327d4" /> ## Testing Tested with `opencode` and `orng` themes on light terminal (Ghostty) - selection is now clearly visible with high contrast. ## CI Failures The CI failures (format and test) appear to be pre-existing issues unrelated to this PR - the `dev` branch shows similar intermittent failures. The format failure is related to SDK generation (`openapi.ts` not found), and the test failure is in `tool.patch`, neither of which are touched by this PR. ## Notes This solution was developed with assistance from Claude Opus 4.5 and may not be the preferred approach by maintainers. A simpler solution might involve updating the default selection color handling in `@opentui/core` itself to better handle light terminal scenarios. However, this PR provides a working solution that I'm using in my local build in the interim, and at minimum demonstrates the issue and one viable fix.
yindo added the pull-request label 2026-02-16 18:16:09 -05:00
yindo closed this issue 2026-02-16 18:16:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11329