Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ export function DiffViewerFileTree(props: DiffViewerFileTreeProps) {
backgroundColor={highlighted() ? props.theme.primary : undefined}
onMouseUp={() => props.onRowClick?.(row)}
>
<text fg={highlighted() ? props.theme.background : fadedColor()} wrapMode="none" flexShrink={0}>
<text fg={highlighted() ? props.theme.selectedListItemText : fadedColor()} wrapMode="none" flexShrink={0}>
{prefix()}
</text>
<box flexGrow={1} minWidth={0}>
<text
fg={
highlighted()
? props.theme.background
? props.theme.selectedListItemText
: selected()
? props.theme.primary
: reviewed() || row.kind === "directory"
Expand All @@ -105,7 +105,7 @@ export function DiffViewerFileTree(props: DiffViewerFileTreeProps) {
</text>
</box>
<text
fg={highlighted() ? props.theme.background : props.theme.textMuted}
fg={highlighted() ? props.theme.selectedListItemText : props.theme.textMuted}
wrapMode="none"
flexShrink={0}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/tui/src/routes/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ function UserMessage(props: {
const directory = file.mime === "application/x-directory"
return (
<text fg={theme.text}>
<span style={{ bg: theme.secondary, fg: theme.background }}>
<span style={{ bg: theme.secondary, fg: selectedForeground(theme, theme.secondary) }}>
{directory ? " Directory " : " File "}
</span>
<span style={{ bg: theme.backgroundElement, fg: theme.textMuted }}> {file.filename} </span>
Expand Down
12 changes: 8 additions & 4 deletions packages/tui/src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ export function selectedForeground(theme: Theme, bg?: RGBA): RGBA {

// For transparent backgrounds, calculate contrast based on the actual bg (or fallback to primary)
if (theme.background.a === 0) {
const targetColor = bg ?? theme.primary
const { r, g, b } = targetColor
const luminance = 0.299 * r + 0.587 * g + 0.114 * b
return luminance > 0.5 ? RGBA.fromInts(0, 0, 0) : RGBA.fromInts(255, 255, 255)
return contrastForeground(bg ?? theme.primary)
}

// Fall back to background color
return theme.background
}

function contrastForeground(bg: RGBA): RGBA {
const luminance = 0.299 * bg.r + 0.587 * bg.g + 0.114 * bg.b
return luminance > 0.5 ? RGBA.fromInts(0, 0, 0) : RGBA.fromInts(255, 255, 255)
}

type HexColor = `#${string}`
type RefName = string
type Variant = {
Expand Down Expand Up @@ -275,6 +277,8 @@ export function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {
const hasSelectedListItemText = theme.theme.selectedListItemText !== undefined
if (hasSelectedListItemText) {
resolved.selectedListItemText = resolveColor(theme.theme.selectedListItemText!)
} else if (resolved.background?.a === 0) {
resolved.selectedListItemText = contrastForeground(resolved.primary ?? RGBA.fromInts(0, 0, 0))
} else {
// Backward compatibility: if selectedListItemText is not defined, use background color
// This preserves the current behavior for all existing themes
Expand Down
Loading