feat(tui): add theme-configurable text selection colors #5296
+107
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5295
Add
selectionandselectionForegroundproperties 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/corebehavior 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
selectionandselectionForegroundproperties to the theme schemaselectiondefaults to theme'sprimarycolorselectionForegroundauto-calculated based on luminance for contrastTheme 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 logicorng.json: Add explicit selection colors as examplesession/index.tsx: PassselectionBg/selectionFgprops to text componentsScreenshots
1.0.137 Unreadable Text Selection:
Examples of PR Solution:
Testing
Tested with
opencodeandorngthemes 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
devbranch shows similar intermittent failures. The format failure is related to SDK generation (openapi.tsnot found), and the test failure is intool.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/coreitself 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.