aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-19 23:10:48 -0800
committerFuwn <[email protected]>2026-01-19 23:10:48 -0800
commit2df87c91c19b2da201500248770054fc11ef5077 (patch)
tree944cda5ad73c6a8d74f9b549a9ca8e589cc6e533 /internal
parentfeat: Add OpenCode-compatible theme loader (diff)
downloadkaze-2df87c91c19b2da201500248770054fc11ef5077.tar.xz
kaze-2df87c91c19b2da201500248770054fc11ef5077.zip
fix: Support both single-color and dual-mode theme formats
Update theme parser to handle both OpenCode theme formats: 1. Dual-mode: {"dark": "color", "light": "color"} - opencode.json 2. Single-color: "color" - ayu.json and other dark-only themes When a single color is provided, use it for both light and dark modes. Fixes parsing error when loading themes like ayu.json.
Diffstat (limited to 'internal')
-rw-r--r--internal/theme/theme.go34
1 files changed, 24 insertions, 10 deletions
diff --git a/internal/theme/theme.go b/internal/theme/theme.go
index cddcaa4..10d6828 100644
--- a/internal/theme/theme.go
+++ b/internal/theme/theme.go
@@ -11,9 +11,9 @@ import (
// OpenCodeTheme represents an OpenCode-compatible theme JSON structure
type OpenCodeTheme struct {
- Schema string `json:"$schema"`
- Defs map[string]string `json:"defs"`
- Theme map[string]OpenCodeThemeMode `json:"theme"`
+ Schema string `json:"$schema"`
+ Defs map[string]string `json:"defs"`
+ Theme map[string]json.RawMessage `json:"theme"` // Can be string or object
}
// OpenCodeThemeMode represents dark/light mode values for a theme property
@@ -66,14 +66,28 @@ func LoadTheme(themeURL string) (*ResolvedTheme, error) {
Light: make(map[string]string),
}
- for key, mode := range ocTheme.Theme {
- // Resolve dark mode color
- darkColor := resolveColor(mode.Dark, ocTheme.Defs)
- resolved.Dark[key] = darkColor
+ for key, rawValue := range ocTheme.Theme {
+ // Try to parse as object first (light/dark mode)
+ var mode OpenCodeThemeMode
+ if err := json.Unmarshal(rawValue, &mode); err == nil && (mode.Dark != "" || mode.Light != "") {
+ // It's an object with dark/light properties
+ darkColor := resolveColor(mode.Dark, ocTheme.Defs)
+ resolved.Dark[key] = darkColor
- // Resolve light mode color
- lightColor := resolveColor(mode.Light, ocTheme.Defs)
- resolved.Light[key] = lightColor
+ lightColor := resolveColor(mode.Light, ocTheme.Defs)
+ resolved.Light[key] = lightColor
+ } else {
+ // It's a simple string (dark-only theme)
+ var colorRef string
+ if err := json.Unmarshal(rawValue, &colorRef); err != nil {
+ continue // Skip invalid values
+ }
+
+ // Use the same color for both light and dark
+ color := resolveColor(colorRef, ocTheme.Defs)
+ resolved.Dark[key] = color
+ resolved.Light[key] = color
+ }
}
return resolved, nil