mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(tui): draw paste chip text dark in dark mode and light in light mode (#62930)
This commit is contained in:
committed by
GitHub
Unverified
parent
52c27fd816
commit
f352b08437
@@ -13,11 +13,15 @@ export function generateSyntax(theme: ResolvedThemeTokens, owner: NativeResource
|
||||
rule(["extmark.file"], feedback.warning.base, { bold: true }),
|
||||
rule(["extmark.agent"], theme.categorical[0][step], { bold: true }),
|
||||
rule(["extmark.skill"], (theme.categorical[1] ?? theme.categorical[0])[step], { bold: true }),
|
||||
// V1 migration preserves its selected/inverse foreground in this action state.
|
||||
rule(["extmark.paste"], theme.text.action.primary.focused, {
|
||||
background: feedback.warning.base,
|
||||
bold: true,
|
||||
}),
|
||||
rule(
|
||||
["extmark.paste"],
|
||||
// The page color: dark in dark mode, light in light mode. A transparent page (the system theme) falls back to the selected-row text.
|
||||
theme.background.base.a === 1 ? theme.background.base : theme.text.action.primary.focused,
|
||||
{
|
||||
background: feedback.warning.base,
|
||||
bold: true,
|
||||
},
|
||||
),
|
||||
rule(["comment", "comment.documentation"], syntax.comment, { italic: true }),
|
||||
rule(["string", "symbol", "character.special", "character"], syntax.string),
|
||||
rule(["number", "boolean", "constant", "float"], syntax.number),
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
type ResolvedTheme,
|
||||
type ThemeDefinition,
|
||||
} from "@opencode/theme/tui"
|
||||
import { getOpenCodeTheme, parseTheme, type ThemeDocumentSource } from "../../../src/theme"
|
||||
import { getOpenCode2Theme, getOpenCodeTheme, parseTheme, type ThemeDocumentSource } from "../../../src/theme"
|
||||
|
||||
const opencodeLight = selectTheme(getOpenCodeTheme(), "light")
|
||||
const opencodeDark = selectTheme(getOpenCodeTheme(), "dark")
|
||||
@@ -120,6 +120,24 @@ test("generates syntax with one categorical hue", () => {
|
||||
}
|
||||
})
|
||||
|
||||
test("draws paste chip text dark in dark mode and light in light mode", () => {
|
||||
for (const mode of ["dark", "light"] as const) {
|
||||
const theme = resolveThemeDocument(getOpenCode2Theme(), mode)
|
||||
const owner = new ResourceContext({ objectCapacity: 1, renderCellsMax: 1 })
|
||||
const syntax = generateSyntax(theme, owner)
|
||||
try {
|
||||
const style = syntax.getStyle("extmark.paste")!
|
||||
expect(style.bg!.equals(theme.text.feedback.warning.base)).toBeTrue()
|
||||
const luminance = (color: RGBA) => 0.299 * color.r + 0.587 * color.g + 0.114 * color.b
|
||||
if (mode === "dark") expect(luminance(style.fg!)).toBeLessThan(luminance(style.bg!))
|
||||
else expect(luminance(style.fg!)).toBeGreaterThan(luminance(style.bg!))
|
||||
} finally {
|
||||
syntax.destroy()
|
||||
owner.destroy()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test("rejects incomplete themes instead of merging defaults", () => {
|
||||
expect(() => resolveSource({ light: { hue: light.hue } }, "light")).toThrow("Invalid theme")
|
||||
expect(() => resolveSource({ light: { ...light, categorical: undefined } }, "light")).toThrow(
|
||||
|
||||
Reference in New Issue
Block a user