GeezerVison is showing github.com — tui: table cell text does not invert when selected · Issue #60686 · anomalyco/opencode
tui: table cell text does not invert when selected #60686DescriptionSummary
In the TUI, selecting text that covers a markdown table does not invert the
foreground of the table cells. The selection background is painted dark while
the cell text keeps its own color, so in light themes the selection becomes
dark-on-dark and unreadable. Plain paragraph text inside the same selection
inverts correctly.
Environment
- opencode version: 2.2.4
- OS: Darwin 27.2.0 (darwin arm64)
- Terminal: Ghostty (TERM=xterm-256color, TERM_PROGRAM=ghostty, COLORTERM=truecolor)
- Shell: /bin/zsh
- Install/channel: release (latest)
- Active plugins: none
Reproduction
- Start the TUI with a light theme (e.g. built-in
opencode theme, mode light).
- Produce an assistant message that contains a markdown table.
- Drag-select a region that includes table cells, either starting inside the
table or starting in the paragraph above it and dragging down across the table.
- Observe the selected table cells.
Expected Behavior
All selected text should remain readable. For text in the selection the
foreground should be inverted/high-contrast against the selection background,
same as regular paragraph text in the same selection.
Actual Behavior
Paragraph text in the selection turns light on a dark selection background, but
table cell text keeps its original color (dark gray / token color) on the same
dark selection background, producing unreadable dark-on-dark text. The cell
text never inverts, regardless of where the selection starts.
Additional Context
- Reproducible consistently; not intermittent.
- Starting the drag outside the table and dragging across it does not change the
result, so it is not related to where the selection anchor is placed.
- The clipboard content is correct; only the rendering is wrong.
- Related observation: overriding
text.muted (the documented token for
secondary text) in a custom V2 theme does not change the table cell text
color, which suggests table cells are styled through a different path.
In the bundled @opentui/core, table cells are built via
createTableDataCellChunks -> renderInlineContent -> createDefaultChunk(text, "default"),
i.e. they use the syntax style named default (and markup.heading for
header cells) rather than the semantic theme tokens.
packages/tui/src/util/selection.ts special-cases selection.behavior === "cell"
only for copy behavior, not for color inversion.
- Workaround: select and copy as usual; the copied text is correct. There is no
theme-level workaround because any explicit cell color is excluded from the
inversion.
Activityopencodejr commented on Oct 30, 2026 Thanks for the detailed report. I can reproduce this on 2.2.4, and it still happens on the latest dev (ad71144).
I used the built-in opencode theme in light mode, with an assistant reply made of a paragraph, a markdown table and a closing paragraph. Dragging from the paragraph down across the table gives:
- paragraph: white text on the #1a1a1a selection background, so it is readable
- table body cells: black (#000000) text on the same #1a1a1a background, so they can't be read
- header cells: black text on the heading orange
The recording and screenshots below show this. The script below reproduces it with a simulated model. As you noted, copying still works; only the drawing of selected table cells is wrong. Related: #41281 (light-mode selection readability in general, closed without changes).
recording.mp4


Reproduction script (drive.ts)
// Repro for anomalyco/opencode#60686: selected markdown table cells do not invert in light theme.
import { Effect, Stream } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
const reply = [
"Here is a short paragraph of plain text above the table so the selection covers both.",
"",
"| Name | Role | Status |",
"|-------|----------|--------|",
"| Alice | Engineer | Active |",
"| Bob | Designer | Away |",
"| Carol | Manager | Active |",
"",
"And a closing paragraph below the table.",
].join("\n")
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
tuiConfig: { theme: { name: "opencode", mode: "light" } },
tui: { recording: true, pointerOverlay: true, viewport: { cols: 120, rows: 40 } },
} as any,
({ ui, llm }) =>
Effect.gen(function* () {
yield* llm.serve(() => Stream.make(Llm.text(reply)))
yield* ui.submit("Show me a table")
yield* Effect.sleep(4000)
yield* ui.screenshot("after-reply")
yield* Effect.sleep(800)
yield* ui.screenshot("before-selection")
const frame: any = yield* ui.capture()
const lines: string[] = frame.lines.map((l: any) => l.spans.map((sp: any) => sp.text).join(""))
const find = (s: string) => lines.findIndex((l) => typeof l === "string" && l.includes(s))
let top = find("plain text above the table")
let bottom = find("Carol")
if (top < 0) top = 5
if (bottom < 0) bottom = top + 10
const x0 = Math.max(0, (lines[top] ?? "").indexOf("Here"))
yield* ui.mouse({ action: "move", x: x0, y: top })
yield* ui.mouse({ action: "down", x: x0, y: top, button: "left" })
for (let y = top; y <= bottom; y++) {
yield* ui.mouse({ action: "move", x: 60, y })
yield* Effect.sleep(80)
}
yield* Effect.sleep(500)
yield* ui.screenshot("selection-held")
const held: any = yield* ui.capture()
const hex = (n: number) => "#" + n.toString(16).padStart(6, "0")
for (const word of ["paragraph", "Alice", "Engineer", "Bob", "Name"]) {
for (const l of held.lines) for (const sp of l.spans)
if (sp.text.includes(word)) yield* Effect.log(`${word}: fg=${hex(sp.fg)} bg=${hex(sp.bg)} text=${JSON.stringify(sp.text)}`)
}
yield* ui.mouse({ action: "up", x: 60, y: bottom, button: "left" })
yield* Effect.sleep(800)
yield* ui.screenshot("selection-released")
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Celebridge commented on Oct 30, 2026 Additional finding that narrows this down to the table renderable's selection options.
TableBlock in @opentui/core has its own selection styling options, both defaulting to undefined:
selectionBg: undefined,
selectionFg: undefined,
On selection it forwards them per cell to the text buffer:
cell.textBufferView.setLocalSelection(anchorX, anchorY, focusX, focusY, this._selectionBg, this._selectionFg)
So table cells do not share the global text-selection path (default fg/bg swap); they go through a per-cell local selection whose colors come from those two options.
When both are undefined, the text buffer derives its own contrasting pair. Observed behavior suggests that derivation assumes a dark page:
- dark theme: derived selection bg is light, derived selection fg is dark -> correct inversion
- light theme: derived selection bg is dark and the derived fg stays dark -> foreground and background collapse
This is why no theme change affects it: the table never receives selectionBg/selectionFg from the host, so it never sees the theme's selection colors.
Possible fixes, in order of correctness:
- Derive the contrast pair from the actual selection background luminance instead of assuming a dark page.
- Let the host pass
selectionBg/selectionFg to the markdown/table renderable, using the theme's selection colors (the same pair the code and diff renderables already accept).
Before/after is consistent: paragraph text in the same selection inverts correctly in both modes; only table cells are affected, and only in light themes.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|