GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): draw text selections in theme colours by neriousy · Pull Request #65776 · anomalyco/opencode

Conversation

@neriousy

@neriousy neriousy commented Nov 23, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes #55094

Selected text in the TUI is now drawn in theme colours. On light themes a selection used to be black text on a near-black block, which was unreadable.

Uses the renderer selection colours from anomalyco/opentui#2196, released in @opentui/core 0.9.8 (dev is on 0.9.9).

Before / after

The opencode theme, selecting part of an assistant reply and part of the prompt.

Light

Before and after, light mode

Dark

Before and after, dark mode

Why it happened

The TUI never passed selection colours to opentui, so every selection fell back to inverting the cell: the highlight took the text colour and the text went black when the cell had no opaque background. On a light theme the text colour is dark, so the selection was black on near-black. #13352 fixed this by passing colours to individual elements. That was turned down in favour of defaults on the renderer, which anomalyco/opentui#2196 adds.

What changed

  • Theme tokens. text.selection and background.selection are new optional tokens in @opencode/theme: schema, expansion and resolved types. By default they use the focused primary action (text.action.primary.$focused on background.action.primary.$focused), which is how the TUI already draws the focused row in lists and the command palette. Built-in themes, v1 themes, the generated system theme and custom themes all get readable colours without changes, and a theme can still set its own.
  • Renderer. context/theme.tsx sets the renderer's selection colours from the active theme, next to the existing setBackgroundColor effect, so they follow theme and mode changes. Elements that set their own colours keep them.
  • Docs. cli/theme.mdx and themes.mdx list the new tokens and their default.

Mini mode doesn't capture the mouse, so its selections are drawn by the terminal and nothing changes there. The Rust TUI's theme (packages/cli-rs) doesn't have these tokens yet.

No feature flag: this is a bug fix.

Verification

  • test/theme/v2/resolve.test.ts checks that the default follows the focused primary action, that a theme's own values win, and that every built-in theme resolves an opaque selection, with at least 4.5:1 contrast for opencode and system in both modes.
  • bun typecheck passes in packages/tui and packages/theme on current dev (@opentui/core 0.9.9).
  • bun test in packages/tui: 1,728 pass, 2 fail. Both failures are in dialog-shell-output.test.tsx and fail the same way on dev without this change.
  • I took the screenshots with opencode-drive, running the TUI from this branch. Before is dev.

Added by the opencode bot (AI-generated).

Related: #60686

Public API: adds optional text.selection / background.selection theme tokens (backwards compatible for theme files)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@neriousy neriousy mentioned this pull request Nov 23, 2026
core: let the renderer set default selection colours anomalyco/opentui#2196
Merged
kommander pushed a commit to anomalyco/opentui that referenced this pull request Nov 23, 2026
@neriousy @simonklee
core: let the renderer set default selection colours (#2196)
141c2c9
Renderables that set no `selectionBg` or `selectionFg` of their own now
take them from the renderer. An app sets them once instead of on every
text renderable, as suggested in anomalyco/opencode#13352.

```ts
const renderer = await createCliRenderer({ selectionBg: "#d3ddf8", selectionFg: "#101010" })
renderer.setSelectionColors("#23344b", "#ffffff") // e.g. when the app's theme changes
renderer.setSelectionColors(undefined, undefined) // back to inverted cells
```

## Why

Without selection colours, a selection inverts its cells, and on a cell
with no opaque background it forces the text to black. opencode keeps
the renderer background transparent and paints its own, so on a light
theme every selection is black text on near-black
(anomalyco/opencode#55094). Passing colours to each of the app's text
renderables was turned down in #13352 in favour of defaults on the
renderer.

## What changed

- `CliRendererConfig` takes `selectionBg` and `selectionFg`.
`CliRenderer` exposes them as `selectionBg`/`selectionFg` and sets them
with `setSelectionColors(bg, fg)`.
- `RenderContext` has optional, read-only `selectionBg` and
`selectionFg`, so other contexts don't need them.
- `TextBufferRenderable` (Text, Code, and the Code views inside Markdown
and Diff), `EditBufferRenderable` (Textarea, Input) and `TextTable` use
their own colour when set and the renderer's otherwise, per colour.
Their `selectionBg`/`selectionFg` getters still return only what was set
on the renderable.
- `setSelectionColors` repaints an active selection, so a theme change
mid-selection takes effect at once.
- Without renderer colours nothing changes: the selection still inverts.

ASCIIFont is unchanged. Without its own colours it draws no highlight,
and it doesn't invert either. The Rust crates have no renderer-level
selection colours yet; I left them for a follow-up.

## Tests

`src/tests/renderer.selection-colors.test.ts` checks the painted cells
for Text and Textarea with renderer colours, a renderable's own colour
winning, an active selection repainted by `setSelectionColors`, and
inversion coming back after clearing. All 5 fail before this change.

- `bun test` in `packages/core`: 7,338 pass, 1 fail. The failure is
`getNodeAssets > returns a deterministic key-sorted manifest for the
host`, which fails on `main` too.
- `bun run typecheck`, `bun run fmt:check`, `bun run lint` pass.

I also checked it end to end in opencode on top of v0.9.4 with this
commit cherry-picked. The opencode side, with before and after
screenshots, is anomalyco/opencode#65776.

---------

Co-authored-by: Simon Klee <[email protected]>
Dicklesworthstone pushed a commit to Dicklesworthstone/opentui that referenced this pull request Nov 23, 2026
@neriousy @simonklee @Dicklesworthstone
core: let the renderer set default selection colours (anomalyco#2196)
eeb15bb
Renderables that set no `selectionBg` or `selectionFg` of their own now
take them from the renderer. An app sets them once instead of on every
text renderable, as suggested in anomalyco/opencode#13352.

```ts
const renderer = await createCliRenderer({ selectionBg: "#d3ddf8", selectionFg: "#101010" })
renderer.setSelectionColors("#23344b", "#ffffff") // e.g. when the app's theme changes
renderer.setSelectionColors(undefined, undefined) // back to inverted cells
```

## Why

Without selection colours, a selection inverts its cells, and on a cell
with no opaque background it forces the text to black. opencode keeps
the renderer background transparent and paints its own, so on a light
theme every selection is black text on near-black
(anomalyco/opencode#55094). Passing colours to each of the app's text
renderables was turned down in #13352 in favour of defaults on the
renderer.

## What changed

- `CliRendererConfig` takes `selectionBg` and `selectionFg`.
`CliRenderer` exposes them as `selectionBg`/`selectionFg` and sets them
with `setSelectionColors(bg, fg)`.
- `RenderContext` has optional, read-only `selectionBg` and
`selectionFg`, so other contexts don't need them.
- `TextBufferRenderable` (Text, Code, and the Code views inside Markdown
and Diff), `EditBufferRenderable` (Textarea, Input) and `TextTable` use
their own colour when set and the renderer's otherwise, per colour.
Their `selectionBg`/`selectionFg` getters still return only what was set
on the renderable.
- `setSelectionColors` repaints an active selection, so a theme change
mid-selection takes effect at once.
- Without renderer colours nothing changes: the selection still inverts.

ASCIIFont is unchanged. Without its own colours it draws no highlight,
and it doesn't invert either. The Rust crates have no renderer-level
selection colours yet; I left them for a follow-up.

## Tests

`src/tests/renderer.selection-colors.test.ts` checks the painted cells
for Text and Textarea with renderer colours, a renderable's own colour
winning, an active selection repainted by `setSelectionColors`, and
inversion coming back after clearing. All 5 fail before this change.

- `bun test` in `packages/core`: 7,338 pass, 1 fail. The failure is
`getNodeAssets > returns a deterministic key-sorted manifest for the
host`, which fails on `main` too.
- `bun run typecheck`, `bun run fmt:check`, `bun run lint` pass.

I also checked it end to end in opencode on top of v0.9.4 with this
commit cherry-picked. The opencode side, with before and after
screenshots, is anomalyco/opencode#65776.

---------

Co-authored-by: Simon Klee <[email protected]>
(cherry picked from commit 141c2c9)
@neriousy
fix(tui): draw text selections in theme colours
3cacd11
@neriousy
neriousy force-pushed the tui-selection-colors branch from 651d88a to 3cacd11 Compare November 26, 2026 14:11
@neriousy
neriousy marked this pull request as ready for review November 26, 2026 14:11
opencodejr[bot]
opencodejr Bot reviewed Nov 26, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. In light mode, selected text is now drawn in the theme's colours (the focused primary action) instead of the inverted dark block. I checked this by running the TUI from each checkout with opencode-drive on the opencode theme in light mode and drag-selecting part of an assistant reply. The before and after screenshots are below. resolve.test.ts passes, and the @opencode/theme type check is clean.

Public API: two optional theme tokens are added, text.selection and background.selection, along with matching required fields on ResolvedThemeTokens in @opencode/theme. Existing theme files keep working without changes, because both tokens default to the focused primary action. Code that builds ResolvedThemeTokens objects by hand would need to add the two new fields.

No blocking concerns.

Related: #60686

Before

After

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@neriousy
neriousy merged commit 586fa90 into dev Nov 26, 2026
24 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@neriousy
neriousy deleted the tui-selection-colors branch November 26, 2026 14:19
@simonklee simonklee mentioned this pull request Nov 26, 2026
fix(cli-rs): port selection colours and ACP fixes, and regenerate bindings #66652
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

tui: text selection highlight is inverted, forcing black text on light themes

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@neriousy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.