mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
feat(tui): add opencode2 theme and text.faint token (#55798)
This commit is contained in:
committed by
GitHub
Unverified
parent
09ef07e11e
commit
c5e513e98e
@@ -41,6 +41,7 @@ function expandText(definition: TextDefinition | undefined): TextDefinition | un
|
||||
return {
|
||||
...definition,
|
||||
muted: definition.muted ?? (definition.base ? "$text.base" : undefined),
|
||||
faint: definition.faint ?? (definition.muted || definition.base ? "$text.muted" : undefined),
|
||||
action: expandActions(definition.action, "text.action"),
|
||||
formfield: expandFormfield(definition.formfield, "text.formfield"),
|
||||
feedback: definition.feedback
|
||||
|
||||
@@ -89,6 +89,7 @@ const BackgroundFeedbackDefinition = Schema.Struct({
|
||||
const TextDefinition = Schema.Struct({
|
||||
base: Schema.optional(ColorValue),
|
||||
muted: Schema.optional(ColorValue),
|
||||
faint: Schema.optional(ColorValue),
|
||||
action: Schema.optional(ActionColorDefinition),
|
||||
formfield: Schema.optional(StatefulColorDefinition),
|
||||
feedback: Schema.optional(
|
||||
@@ -222,6 +223,7 @@ const CompleteThemeTokensDefinition = Schema.Struct({
|
||||
text: Schema.Struct({
|
||||
base: ColorValue,
|
||||
muted: ColorValue,
|
||||
faint: Schema.optional(ColorValue),
|
||||
action: CompleteActionColorDefinition,
|
||||
formfield: CompleteStatefulColorDefinition,
|
||||
feedback: Schema.Struct({
|
||||
|
||||
@@ -31,6 +31,7 @@ export type ResolvedThemeTokens = {
|
||||
readonly text: {
|
||||
readonly base: RGBA
|
||||
readonly muted: RGBA
|
||||
readonly faint: RGBA
|
||||
readonly action: Readonly<Record<ActionVariant, StatefulColor>>
|
||||
readonly formfield: FormfieldColor
|
||||
readonly feedback: Readonly<Record<FeedbackKind, { readonly base: RGBA; readonly muted: RGBA }>>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "@opencode/theme/tui"
|
||||
import {
|
||||
allThemes,
|
||||
getOpenCode2Theme,
|
||||
hasTheme,
|
||||
parseTheme,
|
||||
setCustomThemes,
|
||||
@@ -286,9 +287,16 @@ const themeContext = createSimpleContext({
|
||||
themeRefreshTimeouts.length = 0
|
||||
})
|
||||
|
||||
const available = createMemo((): Record<string, ThemeDocumentSource> =>
|
||||
config.experimental?.["new-designs"] === true
|
||||
? { opencode2: getOpenCode2Theme(), ...themeSources() }
|
||||
: themeSources(),
|
||||
)
|
||||
const has = (name: string) => Boolean(name) && available()[name] !== undefined
|
||||
|
||||
const initStarted = performance.now()
|
||||
const selected = createMemo(() => {
|
||||
const sources = themeSources()
|
||||
const sources = available()
|
||||
const name = sources[store.active] ? store.active : "opencode"
|
||||
try {
|
||||
return loadTheme(sources[name], name, store.mode)
|
||||
@@ -316,8 +324,8 @@ const themeContext = createSimpleContext({
|
||||
get selected() {
|
||||
return store.active
|
||||
},
|
||||
all: allThemes,
|
||||
has: hasTheme,
|
||||
all: available,
|
||||
has,
|
||||
mode,
|
||||
modes,
|
||||
supports: (requested) => modes().includes(requested),
|
||||
@@ -330,7 +338,7 @@ const themeContext = createSimpleContext({
|
||||
return true
|
||||
},
|
||||
set(theme: string) {
|
||||
if (!hasTheme(theme)) return false
|
||||
if (!has(theme)) return false
|
||||
setStore("active", theme)
|
||||
if (theme === "system") refreshPalette()
|
||||
void configState
|
||||
|
||||
@@ -0,0 +1,371 @@
|
||||
{
|
||||
"$schema": "https://opencode.ai/theme.json",
|
||||
"base": {
|
||||
"categorical": [
|
||||
"blue",
|
||||
"purple",
|
||||
"green",
|
||||
"orange",
|
||||
"red"
|
||||
],
|
||||
"text": {
|
||||
"base": "$hue.neutral.100",
|
||||
"muted": "$hue.neutral.200",
|
||||
"faint": "$hue.neutral.300",
|
||||
"action": {
|
||||
"primary": {
|
||||
"base": "$text.base",
|
||||
"$disabled": "$text.faint",
|
||||
"$focused": "$text.base",
|
||||
"$selected": "$hue.interactive.400"
|
||||
},
|
||||
"secondary": {
|
||||
"base": "$text.muted",
|
||||
"$hovered": "$text.base"
|
||||
},
|
||||
"destructive": {
|
||||
"base": "$hue.neutral.900",
|
||||
"$disabled": "$text.faint"
|
||||
}
|
||||
},
|
||||
"formfield": {
|
||||
"base": "$text.base",
|
||||
"$hovered": "$hue.interactive.400",
|
||||
"$focused": "$hue.interactive.400",
|
||||
"$pressed": "$hue.interactive.400",
|
||||
"$disabled": "$text.faint",
|
||||
"$selected": "$hue.interactive.400"
|
||||
},
|
||||
"feedback": {
|
||||
"error": {
|
||||
"base": "$hue.red.400"
|
||||
},
|
||||
"warning": {
|
||||
"base": "#f5a742"
|
||||
},
|
||||
"success": {
|
||||
"base": "$hue.green.400"
|
||||
},
|
||||
"info": {
|
||||
"base": "$hue.blue.400"
|
||||
}
|
||||
}
|
||||
},
|
||||
"background": {
|
||||
"base": "$hue.neutral.900",
|
||||
"raised": {
|
||||
"base": "$hue.neutral.700",
|
||||
"high": "$hue.neutral.600",
|
||||
"max": "$hue.neutral.500"
|
||||
},
|
||||
"action": {
|
||||
"primary": {
|
||||
"base": "transparent",
|
||||
"$hovered": "$hue.neutral.700",
|
||||
"$focused": "$hue.interactive.600",
|
||||
"$selected": "transparent"
|
||||
},
|
||||
"secondary": {
|
||||
"base": "transparent"
|
||||
},
|
||||
"destructive": {
|
||||
"base": "$hue.red.400"
|
||||
}
|
||||
},
|
||||
"formfield": {
|
||||
"base": "$background.base"
|
||||
},
|
||||
"feedback": {
|
||||
"error": {
|
||||
"base": "$background.base"
|
||||
},
|
||||
"warning": {
|
||||
"base": "$background.base"
|
||||
},
|
||||
"success": {
|
||||
"base": "$background.base"
|
||||
},
|
||||
"info": {
|
||||
"base": "$background.base"
|
||||
}
|
||||
}
|
||||
},
|
||||
"border": {
|
||||
"base": "#484848"
|
||||
},
|
||||
"scrollbar": {
|
||||
"base": "#606060"
|
||||
},
|
||||
"diff": {
|
||||
"text": {
|
||||
"added": "#4fd6be",
|
||||
"removed": "#c53b53",
|
||||
"context": "#828bb8",
|
||||
"hunkHeader": "#828bb8"
|
||||
},
|
||||
"background": {
|
||||
"added": "#20303b",
|
||||
"removed": "#37222c",
|
||||
"context": "$hue.neutral.700"
|
||||
},
|
||||
"highlight": {
|
||||
"added": "#b8db87",
|
||||
"removed": "#e26a75"
|
||||
},
|
||||
"lineNumber": {
|
||||
"text": "#8f8f8f",
|
||||
"background": {
|
||||
"added": "#1b2b34",
|
||||
"removed": "#2d1f26"
|
||||
}
|
||||
}
|
||||
},
|
||||
"syntax": {
|
||||
"comment": "#808080",
|
||||
"keyword": "#9d7cd8",
|
||||
"function": "#fab283",
|
||||
"variable": "#e06c75",
|
||||
"string": "#7fd88f",
|
||||
"number": "#f5a742",
|
||||
"type": "#e5c07b",
|
||||
"operator": "#56b6c2",
|
||||
"punctuation": "#eeeeee"
|
||||
},
|
||||
"markdown": {
|
||||
"text": "#eeeeee",
|
||||
"heading": "#9d7cd8",
|
||||
"link": "#fab283",
|
||||
"linkText": "#56b6c2",
|
||||
"code": "#7fd88f",
|
||||
"blockQuote": "#e5c07b",
|
||||
"emphasis": "#e5c07b",
|
||||
"strong": "#f5a742",
|
||||
"horizontalRule": "#808080",
|
||||
"listItem": "#fab283",
|
||||
"listEnumeration": "#56b6c2",
|
||||
"image": "#fab283",
|
||||
"imageText": "#56b6c2",
|
||||
"codeBlock": "#eeeeee"
|
||||
},
|
||||
"@dialog": {
|
||||
"background": {
|
||||
"base": "$background.raised.base",
|
||||
"action": {
|
||||
"primary": {
|
||||
"$hovered": "$background.raised.high"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"light": {
|
||||
"hue": {
|
||||
"gray": {
|
||||
"100": "#101010",
|
||||
"200": "#505050",
|
||||
"300": "#808080",
|
||||
"400": "#b5b5b5",
|
||||
"500": "#cfcfcf",
|
||||
"600": "#dddddd",
|
||||
"700": "#f2f2f2",
|
||||
"800": "#fafafa",
|
||||
"900": "#ffffff"
|
||||
},
|
||||
"blue": {
|
||||
"100": "#1b1f2e",
|
||||
"200": "#6e7380",
|
||||
"300": "#9ba1b2",
|
||||
"400": "#6c8ffe",
|
||||
"500": "#b9c9f5",
|
||||
"600": "#d3ddf8",
|
||||
"700": "#eaf0ff",
|
||||
"800": "#f4f7ff",
|
||||
"900": "#fbfcff"
|
||||
},
|
||||
"orange": {
|
||||
"100": "#2e241b",
|
||||
"200": "#7d7670",
|
||||
"300": "#afa49d",
|
||||
"400": "#c4713a",
|
||||
"500": "#e8c7ad",
|
||||
"600": "#f0dcce",
|
||||
"700": "#fcf2ea",
|
||||
"800": "#fdf8f4",
|
||||
"900": "#fefdfb"
|
||||
},
|
||||
"purple": {
|
||||
"100": "#231b2e",
|
||||
"200": "#74707c",
|
||||
"300": "#a29dae",
|
||||
"400": "#9d78df",
|
||||
"500": "#cdbee7",
|
||||
"600": "#e8e0f8",
|
||||
"700": "#f0ebfa",
|
||||
"800": "#f8f5fc",
|
||||
"900": "#fcfbfe"
|
||||
},
|
||||
"red": {
|
||||
"100": "#2e1b1b",
|
||||
"200": "#7e6d6d",
|
||||
"300": "#b09999",
|
||||
"400": "#ec6262",
|
||||
"500": "#eab8b8",
|
||||
"600": "#fbdada",
|
||||
"700": "#fdeaea",
|
||||
"800": "#fff6f6",
|
||||
"900": "#fffbfb"
|
||||
},
|
||||
"green": {
|
||||
"100": "#1b2e1b",
|
||||
"200": "#6d7e6d",
|
||||
"300": "#99b099",
|
||||
"400": "#62ec62",
|
||||
"500": "#b8eab8",
|
||||
"600": "#dafbda",
|
||||
"700": "#eafdea",
|
||||
"800": "#f6fff6",
|
||||
"900": "#fbfffb"
|
||||
},
|
||||
"accent": "$hue.blue",
|
||||
"interactive": "$hue.blue",
|
||||
"neutral": "$hue.gray"
|
||||
},
|
||||
"text": {
|
||||
"feedback": {
|
||||
"warning": {
|
||||
"base": "#d68c27"
|
||||
}
|
||||
}
|
||||
},
|
||||
"border": {
|
||||
"base": "#b8b8b8"
|
||||
},
|
||||
"scrollbar": {
|
||||
"base": "#a0a0a0"
|
||||
},
|
||||
"diff": {
|
||||
"text": {
|
||||
"added": "#1e725c",
|
||||
"removed": "#c53b53",
|
||||
"context": "#7086b5",
|
||||
"hunkHeader": "#7086b5"
|
||||
},
|
||||
"background": {
|
||||
"added": "#d5e5d5",
|
||||
"removed": "#f7d8db",
|
||||
"context": "$hue.neutral.700"
|
||||
},
|
||||
"highlight": {
|
||||
"added": "#4db380",
|
||||
"removed": "#f52a65"
|
||||
},
|
||||
"lineNumber": {
|
||||
"text": "#595959",
|
||||
"background": {
|
||||
"added": "#c5d5c5",
|
||||
"removed": "#e7c8cb"
|
||||
}
|
||||
}
|
||||
},
|
||||
"syntax": {
|
||||
"comment": "#8a8a8a",
|
||||
"keyword": "#d68c27",
|
||||
"function": "#3b7dd8",
|
||||
"variable": "#d1383d",
|
||||
"string": "#3d9a57",
|
||||
"number": "#d68c27",
|
||||
"type": "#b0851f",
|
||||
"operator": "#318795",
|
||||
"punctuation": "#1a1a1a"
|
||||
},
|
||||
"markdown": {
|
||||
"text": "#1a1a1a",
|
||||
"heading": "#d68c27",
|
||||
"link": "#3b7dd8",
|
||||
"linkText": "#318795",
|
||||
"code": "#3d9a57",
|
||||
"blockQuote": "#b0851f",
|
||||
"emphasis": "#b0851f",
|
||||
"strong": "#d68c27",
|
||||
"horizontalRule": "#8a8a8a",
|
||||
"listItem": "#3b7dd8",
|
||||
"listEnumeration": "#318795",
|
||||
"image": "#3b7dd8",
|
||||
"imageText": "#318795",
|
||||
"codeBlock": "#1a1a1a"
|
||||
}
|
||||
},
|
||||
"dark": {
|
||||
"hue": {
|
||||
"gray": {
|
||||
"100": "#ffffff",
|
||||
"200": "#b0b0b0",
|
||||
"300": "#808080",
|
||||
"400": "#444444",
|
||||
"500": "#303030",
|
||||
"600": "#202020",
|
||||
"700": "#141414",
|
||||
"800": "#101010",
|
||||
"900": "#080808"
|
||||
},
|
||||
"blue": {
|
||||
"100": "#f1f4ff",
|
||||
"200": "#93a2b7",
|
||||
"300": "#6d7a8d",
|
||||
"400": "#7699fe",
|
||||
"500": "#426097",
|
||||
"600": "#23344b",
|
||||
"700": "#162333",
|
||||
"800": "#0d1621",
|
||||
"900": "#050a12"
|
||||
},
|
||||
"orange": {
|
||||
"100": "#f6f0eb",
|
||||
"200": "#b09c8d",
|
||||
"300": "#807770",
|
||||
"400": "#ecb081",
|
||||
"500": "#896b50",
|
||||
"600": "#42372c",
|
||||
"700": "#2c241d",
|
||||
"800": "#1b1612",
|
||||
"900": "#0d0907"
|
||||
},
|
||||
"purple": {
|
||||
"100": "#f7f2ff",
|
||||
"200": "#af9eba",
|
||||
"300": "#7d7492",
|
||||
"400": "#a383e2",
|
||||
"500": "#685588",
|
||||
"600": "#3b3347",
|
||||
"700": "#241e2c",
|
||||
"800": "#130f18",
|
||||
"900": "#0c080e"
|
||||
},
|
||||
"red": {
|
||||
"100": "#fff2f2",
|
||||
"200": "#b09492",
|
||||
"300": "#90706f",
|
||||
"400": "#ef6c6c",
|
||||
"500": "#90494a",
|
||||
"600": "#4a2e2e",
|
||||
"700": "#2e1f1f",
|
||||
"800": "#1a1313",
|
||||
"900": "#0d0909"
|
||||
},
|
||||
"green": {
|
||||
"100": "#f1f1f1",
|
||||
"200": "#c5cfc5",
|
||||
"300": "#8f9c8f",
|
||||
"400": "#9ee77a",
|
||||
"500": "#499049",
|
||||
"600": "#2c422c",
|
||||
"700": "#1f2e1f",
|
||||
"800": "#131a13",
|
||||
"900": "#090d09"
|
||||
},
|
||||
"accent": "$hue.blue",
|
||||
"interactive": "$hue.blue",
|
||||
"neutral": "$hue.gray"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { migrateV1, parseThemeDocument, type ThemeDocument, type ModeDefinition
|
||||
import { resolveThemeColors } from "./resolve"
|
||||
import { DEFAULT_THEMES, type Theme, type ThemeV1Json } from "./v1"
|
||||
import opencode from "./assets/v2/opencode.json" with { type: "json" }
|
||||
import opencode2 from "./assets/v2/opencode2.json" with { type: "json" }
|
||||
|
||||
export { DEFAULT_THEMES, type Theme, type ThemeV1Json } from "./v1"
|
||||
|
||||
@@ -23,6 +24,15 @@ export function getOpenCodeTheme() {
|
||||
return document
|
||||
}
|
||||
|
||||
let opencode2Theme: ThemeDocument | undefined
|
||||
|
||||
// Temporary theme for the "new-designs" experiment. It is not part of allThemes(), so only the
|
||||
// TUI theme context offers it, and only while the experiment is enabled.
|
||||
export function getOpenCode2Theme() {
|
||||
opencode2Theme ??= parseThemeDocument(opencode2, "opencode2")
|
||||
return opencode2Theme
|
||||
}
|
||||
|
||||
function listThemes(): Record<string, ThemeDocumentSource> {
|
||||
// Priority: defaults < custom files < generated system.
|
||||
const themes: Record<string, ThemeDocumentSource> = {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/** @jsxImportSource @opentui/solid */
|
||||
import { testRender } from "@opentui/solid"
|
||||
import { expect, test } from "bun:test"
|
||||
import { resolveThemeDocument } from "@opencode/theme/tui"
|
||||
import { ConfigProvider, useConfig, type Info } from "../../src/config"
|
||||
import { ThemeProvider, useTheme, useThemes } from "../../src/context/theme"
|
||||
import { getOpenCode2Theme, getOpenCodeTheme } from "../../src/theme"
|
||||
import { emptyThemeSource, tmpdir } from "../fixture/fixture"
|
||||
import { TestTuiContexts } from "../fixture/tui-environment"
|
||||
import { createTuiResolvedConfig } from "../fixture/tui-runtime"
|
||||
|
||||
test("offers opencode2 only while the new designs experiment is enabled", async () => {
|
||||
await using temporary = await tmpdir()
|
||||
const settings: Info = {}
|
||||
let config!: ReturnType<typeof useConfig>
|
||||
let themes!: ReturnType<typeof useThemes>
|
||||
let theme!: ReturnType<typeof useTheme>
|
||||
function Probe() {
|
||||
config = useConfig()
|
||||
themes = useThemes()
|
||||
theme = useTheme()
|
||||
return null
|
||||
}
|
||||
const app = await testRender(() => (
|
||||
<TestTuiContexts paths={{ state: temporary.path }}>
|
||||
<ConfigProvider
|
||||
config={createTuiResolvedConfig(settings)}
|
||||
service={{
|
||||
get: async () => settings,
|
||||
update: async (update) => {
|
||||
update(settings)
|
||||
return settings
|
||||
},
|
||||
}}
|
||||
>
|
||||
<ThemeProvider mode="dark" source={emptyThemeSource}>
|
||||
<Probe />
|
||||
</ThemeProvider>
|
||||
</ConfigProvider>
|
||||
</TestTuiContexts>
|
||||
))
|
||||
|
||||
try {
|
||||
app.renderer.start()
|
||||
await app.waitForFrame(() => themes !== undefined)
|
||||
expect(themes.has("opencode2")).toBeFalse()
|
||||
expect(Object.keys(themes.all())).not.toContain("opencode2")
|
||||
expect(themes.set("opencode2")).toBeFalse()
|
||||
|
||||
await config.update((draft) => {
|
||||
draft.experimental = { "new-designs": true }
|
||||
})
|
||||
expect(themes.has("opencode2")).toBeTrue()
|
||||
expect(themes.set("opencode2")).toBeTrue()
|
||||
expect(theme.background.base.equals(resolveThemeDocument(getOpenCode2Theme(), "dark").background.base)).toBeTrue()
|
||||
|
||||
await config.update((draft) => {
|
||||
draft.experimental = { "new-designs": false }
|
||||
})
|
||||
expect(themes.has("opencode2")).toBeFalse()
|
||||
expect(theme.background.base.equals(resolveThemeDocument(getOpenCodeTheme(), "dark").background.base)).toBeTrue()
|
||||
expect(themes.selected).toBe("opencode2")
|
||||
expect(settings.theme?.name).toBe("opencode2")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
@@ -22,6 +22,11 @@ test("registers opencode as a native V2 theme", () => {
|
||||
expect(parseTheme(getOpenCodeTheme()).base).toBeDefined()
|
||||
})
|
||||
|
||||
test("keeps the experimental opencode2 theme out of the global theme list", () => {
|
||||
expect(allThemes().opencode2).toBeUndefined()
|
||||
expect(hasTheme("opencode2")).toBe(false)
|
||||
})
|
||||
|
||||
test("detects V1 themes from their theme field and caches migrations", () => {
|
||||
const unversioned = structuredClone(opencodeV1)
|
||||
const explicit = { ...structuredClone(opencodeV1), version: 1 }
|
||||
|
||||
@@ -268,6 +268,15 @@ test("resolves matched action variants and states", () => {
|
||||
expect(theme.background.formfield.hovered).toBeInstanceOf(RGBA)
|
||||
})
|
||||
|
||||
test("defaults faint text to muted unless a theme sets it", () => {
|
||||
const fallback = resolveTheme(light)
|
||||
const explicit = resolveTheme({ ...light, text: { ...light.text, faint: "#123456" } })
|
||||
|
||||
expect(fallback.text.faint).toBe(fallback.text.muted)
|
||||
expect(fallback.surface("dialog").text.faint).toBe(fallback.surface("dialog").text.muted)
|
||||
expect(explicit.text.faint.toInts()).toEqual([18, 52, 86, 255])
|
||||
})
|
||||
|
||||
test("resolves dialog surfaces from direct colors", () => {
|
||||
const theme = resolveSource(
|
||||
{
|
||||
|
||||
@@ -174,7 +174,7 @@ Semantic tokens assign colors to UI roles. Components use these roles instead of
|
||||
|
||||
| Group | Purpose |
|
||||
| --- | --- |
|
||||
| `text` | Base, muted, action, form-field, status, and feedback text. |
|
||||
| `text` | Base, muted, faint, action, form-field, status, and feedback text. `faint` defaults to `muted`. |
|
||||
| `background` | Base, raised surfaces, actions, form fields, and feedback fills. |
|
||||
| `border`, `scrollbar` | Border and scrollbar colors. |
|
||||
| `diff` | Added, removed, context, highlight, and line-number colors. |
|
||||
|
||||
Reference in New Issue
Block a user