Skip to content

Conversation

@ben-vargas
Copy link
Contributor

@ben-vargas ben-vargas commented Dec 9, 2025

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 ben-vargas force-pushed the feat-selected-text-theme-color branch 4 times, most recently from 29ab89a to bca7110 Compare December 18, 2025 23:03
@ben-vargas ben-vargas force-pushed the feat-selected-text-theme-color branch from bca7110 to 08130d3 Compare December 24, 2025 04:53
Add selection and selectionForeground properties to the theme system
to fix poor contrast when selecting text in themes like orng.

Changes:
- Add selection/selectionForeground to ThemeColors type
- Add smart fallbacks: selection defaults to primary color,
  foreground auto-calculated based on luminance for contrast
- Update orng.json with explicit high-contrast selection colors
- Pass selectionBg/selectionFg props to all text-rendering components
  in session view (code blocks, text, diff, user messages, tool output)

Themes without explicit selection colors get sensible defaults.
Theme authors can customize via selection/selectionForeground properties.
@ben-vargas ben-vargas force-pushed the feat-selected-text-theme-color branch from 08130d3 to e1861bf Compare December 26, 2025 18:23
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.

Text selection has poor contrast/readability on light terminals with certain themes

1 participant