Skip to content

Commit bd112fa

Browse files
author
saravmajestic
committed
fix: improve light terminal detection and text contrast
- Add COLORFGBG env var fallback when OSC 11 detection times out - Use dark foreground (#1a1a1a) instead of palette[7] (#c0c0c0) for light mode system theme - Use backgroundElement for inline code blocks to ensure contrast on transparent backgrounds Closes #704
1 parent adaebe0 commit bd112fa

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,20 @@ async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
165165

166166
timeout = setTimeout(() => {
167167
cleanup()
168+
// altimate_change start — fix: use COLORFGBG env var as fallback before defaulting to dark
169+
// Many terminals (iTerm2, xterm, etc.) set COLORFGBG=<fg>;<bg> to indicate color scheme.
170+
// When bg component >= 8, the terminal likely has a light background.
171+
const colorfgbg = process.env.COLORFGBG
172+
if (colorfgbg) {
173+
const parts = colorfgbg.split(";")
174+
const bg = parseInt(parts[parts.length - 1])
175+
if (!isNaN(bg) && bg >= 8) {
176+
resolve("light")
177+
return
178+
}
179+
}
168180
resolve("dark")
181+
// altimate_change end
169182
}, 1000)
170183
})
171184
}

packages/opencode/src/cli/cmd/tui/context/theme.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,15 @@ export function tint(base: RGBA, overlay: RGBA, alpha: number): RGBA {
430430

431431
function generateSystem(colors: TerminalColors, mode: "dark" | "light"): ThemeJson {
432432
const bg = RGBA.fromHex(colors.defaultBackground ?? colors.palette[0]!)
433-
const fg = RGBA.fromHex(colors.defaultForeground ?? colors.palette[7]!)
434433
const transparent = RGBA.fromInts(0, 0, 0, 0)
435434
const isDark = mode == "dark"
436435

436+
// altimate_change start — fix: use contrast-appropriate fallback for light terminals
437+
// palette[7] is #c0c0c0 (light gray) which is invisible on white backgrounds
438+
const fgFallback = isDark ? colors.palette[7]! : "#1a1a1a"
439+
const fg = RGBA.fromHex(colors.defaultForeground ?? fgFallback)
440+
// altimate_change end
441+
437442
const col = (i: number) => {
438443
const value = colors.palette[i]
439444
if (value) return RGBA.fromHex(value)
@@ -948,7 +953,10 @@ function getSyntaxRules(theme: Theme) {
948953
scope: ["markup.raw.inline"],
949954
style: {
950955
foreground: theme.markdownCode,
951-
background: theme.background, // inline code blends with page background
956+
// altimate_change start — fix: use backgroundElement for inline code contrast on light themes
957+
// theme.background can be transparent, leaving inline code with no contrast protection
958+
background: theme.backgroundElement,
959+
// altimate_change end
952960
},
953961
},
954962
{

0 commit comments

Comments
 (0)