opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(tui): add theme-configurable text selection colors

Open ben-vargas opened this issue 2 weeks ago • 0 comments

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.

ben-vargas avatar Dec 09 '25 21:12 ben-vargas