opencode/run: refresh themes after terminal reloads (#30917)

This commit is contained in:
Simon Klee 2026-06-05 11:47:17 +02:00 committed by GitHub
commit 0c0d193474
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 499 additions and 71 deletions

View file

@ -1,6 +1,7 @@
import { expect, test } from "bun:test"
import type { TerminalColors } from "@opentui/core"
const { DEFAULT_THEMES, allThemes, addTheme, hasTheme, resolveTheme } = await import(
const { DEFAULT_THEMES, allThemes, addTheme, hasTheme, resolveTheme, terminalMode } = await import(
"../../../src/cli/cmd/tui/context/theme"
)
@ -49,3 +50,27 @@ test("resolveTheme rejects circular color refs", () => {
expect(() => resolveTheme(item, "dark")).toThrow("Circular color reference")
})
function terminalColors(defaultBackground: string | null, palette: Array<string | null> = []): TerminalColors {
return {
palette,
defaultForeground: null,
defaultBackground,
cursorColor: null,
mouseForeground: null,
mouseBackground: null,
tekForeground: null,
tekBackground: null,
highlightBackground: null,
highlightForeground: null,
}
}
test("terminalMode derives mode from refreshed background", () => {
expect(terminalMode(terminalColors("#fbf1c7"))).toBe("light")
expect(terminalMode(terminalColors("#1a1b26"))).toBe("dark")
})
test("terminalMode does not derive mode from ANSI slot zero", () => {
expect(terminalMode(terminalColors(null, ["#000000"]))).toBeUndefined()
})