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
48 changes: 43 additions & 5 deletions packages/opencode/src/cli/cmd/tui/context/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type ThemeColors = {
syntaxType: RGBA
syntaxOperator: RGBA
syntaxPunctuation: RGBA
syntaxTag: RGBA
syntaxAttribute: RGBA
syntaxTagDelimiter: RGBA
}

type Theme = ThemeColors & {
Expand Down Expand Up @@ -127,9 +130,15 @@ type ColorValue = HexColor | RefName | Variant | RGBA
type ThemeJson = {
$schema?: string
defs?: Record<string, HexColor | RefName>
theme: Omit<Record<keyof ThemeColors, ColorValue>, "selectedListItemText" | "backgroundMenu"> & {
theme: Omit<
Record<keyof ThemeColors, ColorValue>,
"selectedListItemText" | "backgroundMenu" | "syntaxTag" | "syntaxAttribute" | "syntaxTagDelimiter"
> & {
selectedListItemText?: ColorValue
backgroundMenu?: ColorValue
syntaxTag?: ColorValue
syntaxAttribute?: ColorValue
syntaxTagDelimiter?: ColorValue
thinkingOpacity?: number
}
}
Expand Down Expand Up @@ -193,7 +202,15 @@ function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {

const resolved = Object.fromEntries(
Object.entries(theme.theme)
.filter(([key]) => key !== "selectedListItemText" && key !== "backgroundMenu" && key !== "thinkingOpacity")
.filter(
([key]) =>
key !== "selectedListItemText" &&
key !== "backgroundMenu" &&
key !== "thinkingOpacity" &&
key !== "syntaxTag" &&
key !== "syntaxAttribute" &&
key !== "syntaxTagDelimiter",
)
.map(([key, value]) => {
return [key, resolveColor(value as ColorValue)]
}),
Expand All @@ -216,6 +233,24 @@ function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {
resolved.backgroundMenu = resolved.backgroundElement
}

if (theme.theme.syntaxTag !== undefined) {
resolved.syntaxTag = resolveColor(theme.theme.syntaxTag)
} else {
resolved.syntaxTag = resolved.error
}

if (theme.theme.syntaxAttribute !== undefined) {
resolved.syntaxAttribute = resolveColor(theme.theme.syntaxAttribute)
} else {
resolved.syntaxAttribute = resolved.syntaxKeyword
}

if (theme.theme.syntaxTagDelimiter !== undefined) {
resolved.syntaxTagDelimiter = resolveColor(theme.theme.syntaxTagDelimiter)
} else {
resolved.syntaxTagDelimiter = resolved.syntaxOperator
}

// Handle thinkingOpacity - optional with default of 0.6
const thinkingOpacity = theme.theme.thinkingOpacity ?? 0.6

Expand Down Expand Up @@ -487,6 +522,9 @@ function generateSystem(colors: TerminalColors, mode: "dark" | "light"): ThemeJs
syntaxType: ansiColors.cyan,
syntaxOperator: ansiColors.cyan,
syntaxPunctuation: fg,
syntaxTag: ansiColors.red,
syntaxAttribute: ansiColors.magenta,
syntaxTagDelimiter: ansiColors.cyan,
},
}
}
Expand Down Expand Up @@ -1018,19 +1056,19 @@ function getSyntaxRules(theme: Theme) {
{
scope: ["tag"],
style: {
foreground: theme.error,
foreground: theme.syntaxTag,
},
},
{
scope: ["tag.attribute"],
style: {
foreground: theme.syntaxKeyword,
foreground: theme.syntaxAttribute,
},
},
{
scope: ["tag.delimiter"],
style: {
foreground: theme.syntaxOperator,
foreground: theme.syntaxTagDelimiter,
},
},
{
Expand Down
12 changes: 12 additions & 0 deletions packages/opencode/src/cli/cmd/tui/context/theme/opencode.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@
"syntaxPunctuation": {
"dark": "darkStep12",
"light": "lightStep12"
},
"syntaxTag": {
"dark": "darkRed",
"light": "lightRed"
},
"syntaxAttribute": {
"dark": "darkAccent",
"light": "lightAccent"
},
"syntaxTagDelimiter": {
"dark": "darkCyan",
"light": "lightCyan"
}
}
}
5 changes: 4 additions & 1 deletion packages/web/public/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
"syntaxNumber": { "$ref": "#/definitions/colorValue" },
"syntaxType": { "$ref": "#/definitions/colorValue" },
"syntaxOperator": { "$ref": "#/definitions/colorValue" },
"syntaxPunctuation": { "$ref": "#/definitions/colorValue" }
"syntaxPunctuation": { "$ref": "#/definitions/colorValue" },
"syntaxTag": { "$ref": "#/definitions/colorValue" },
"syntaxAttribute": { "$ref": "#/definitions/colorValue" },
"syntaxTagDelimiter": { "$ref": "#/definitions/colorValue" }
},
"required": ["primary", "secondary", "accent", "text", "textMuted", "background"],
"additionalProperties": false
Expand Down