GeezerVison is showing github.com — fix: add support for loading custom themes from .opencode/themes dire… · toastdriven/opencode@d81dce6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +223Lines changed: 223 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "$schema": "https://opencode.ai/theme.json", | | 3 | + "defs": { | | 4 | + "nord0": "#2E3440", | | 5 | + "nord1": "#3B4252", | | 6 | + "nord2": "#434C5E", | | 7 | + "nord3": "#4C566A", | | 8 | + "nord4": "#D8DEE9", | | 9 | + "nord5": "#E5E9F0", | | 10 | + "nord6": "#ECEFF4", | | 11 | + "nord7": "#8FBCBB", | | 12 | + "nord8": "#88C0D0", | | 13 | + "nord9": "#81A1C1", | | 14 | + "nord10": "#5E81AC", | | 15 | + "nord11": "#BF616A", | | 16 | + "nord12": "#D08770", | | 17 | + "nord13": "#EBCB8B", | | 18 | + "nord14": "#A3BE8C", | | 19 | + "nord15": "#B48EAD" | | 20 | + }, | | 21 | + "theme": { | | 22 | + "primary": { | | 23 | + "dark": "nord8", | | 24 | + "light": "nord10" | | 25 | + }, | | 26 | + "secondary": { | | 27 | + "dark": "nord9", | | 28 | + "light": "nord9" | | 29 | + }, | | 30 | + "accent": { | | 31 | + "dark": "nord7", | | 32 | + "light": "nord7" | | 33 | + }, | | 34 | + "error": { | | 35 | + "dark": "nord11", | | 36 | + "light": "nord11" | | 37 | + }, | | 38 | + "warning": { | | 39 | + "dark": "nord12", | | 40 | + "light": "nord12" | | 41 | + }, | | 42 | + "success": { | | 43 | + "dark": "nord14", | | 44 | + "light": "nord14" | | 45 | + }, | | 46 | + "info": { | | 47 | + "dark": "nord8", | | 48 | + "light": "nord10" | | 49 | + }, | | 50 | + "text": { | | 51 | + "dark": "nord4", | | 52 | + "light": "nord0" | | 53 | + }, | | 54 | + "textMuted": { | | 55 | + "dark": "nord3", | | 56 | + "light": "nord1" | | 57 | + }, | | 58 | + "background": { | | 59 | + "dark": "nord0", | | 60 | + "light": "nord6" | | 61 | + }, | | 62 | + "backgroundPanel": { | | 63 | + "dark": "nord1", | | 64 | + "light": "nord5" | | 65 | + }, | | 66 | + "backgroundElement": { | | 67 | + "dark": "nord1", | | 68 | + "light": "nord4" | | 69 | + }, | | 70 | + "border": { | | 71 | + "dark": "nord2", | | 72 | + "light": "nord3" | | 73 | + }, | | 74 | + "borderActive": { | | 75 | + "dark": "nord3", | | 76 | + "light": "nord2" | | 77 | + }, | | 78 | + "borderSubtle": { | | 79 | + "dark": "nord2", | | 80 | + "light": "nord3" | | 81 | + }, | | 82 | + "diffAdded": { | | 83 | + "dark": "nord14", | | 84 | + "light": "nord14" | | 85 | + }, | | 86 | + "diffRemoved": { | | 87 | + "dark": "nord11", | | 88 | + "light": "nord11" | | 89 | + }, | | 90 | + "diffContext": { | | 91 | + "dark": "nord3", | | 92 | + "light": "nord3" | | 93 | + }, | | 94 | + "diffHunkHeader": { | | 95 | + "dark": "nord3", | | 96 | + "light": "nord3" | | 97 | + }, | | 98 | + "diffHighlightAdded": { | | 99 | + "dark": "nord14", | | 100 | + "light": "nord14" | | 101 | + }, | | 102 | + "diffHighlightRemoved": { | | 103 | + "dark": "nord11", | | 104 | + "light": "nord11" | | 105 | + }, | | 106 | + "diffAddedBg": { | | 107 | + "dark": "#3B4252", | | 108 | + "light": "#E5E9F0" | | 109 | + }, | | 110 | + "diffRemovedBg": { | | 111 | + "dark": "#3B4252", | | 112 | + "light": "#E5E9F0" | | 113 | + }, | | 114 | + "diffContextBg": { | | 115 | + "dark": "nord1", | | 116 | + "light": "nord5" | | 117 | + }, | | 118 | + "diffLineNumber": { | | 119 | + "dark": "nord2", | | 120 | + "light": "nord4" | | 121 | + }, | | 122 | + "diffAddedLineNumberBg": { | | 123 | + "dark": "#3B4252", | | 124 | + "light": "#E5E9F0" | | 125 | + }, | | 126 | + "diffRemovedLineNumberBg": { | | 127 | + "dark": "#3B4252", | | 128 | + "light": "#E5E9F0" | | 129 | + }, | | 130 | + "markdownText": { | | 131 | + "dark": "nord4", | | 132 | + "light": "nord0" | | 133 | + }, | | 134 | + "markdownHeading": { | | 135 | + "dark": "nord8", | | 136 | + "light": "nord10" | | 137 | + }, | | 138 | + "markdownLink": { | | 139 | + "dark": "nord9", | | 140 | + "light": "nord9" | | 141 | + }, | | 142 | + "markdownLinkText": { | | 143 | + "dark": "nord7", | | 144 | + "light": "nord7" | | 145 | + }, | | 146 | + "markdownCode": { | | 147 | + "dark": "nord14", | | 148 | + "light": "nord14" | | 149 | + }, | | 150 | + "markdownBlockQuote": { | | 151 | + "dark": "nord3", | | 152 | + "light": "nord3" | | 153 | + }, | | 154 | + "markdownEmph": { | | 155 | + "dark": "nord12", | | 156 | + "light": "nord12" | | 157 | + }, | | 158 | + "markdownStrong": { | | 159 | + "dark": "nord13", | | 160 | + "light": "nord13" | | 161 | + }, | | 162 | + "markdownHorizontalRule": { | | 163 | + "dark": "nord3", | | 164 | + "light": "nord3" | | 165 | + }, | | 166 | + "markdownListItem": { | | 167 | + "dark": "nord8", | | 168 | + "light": "nord10" | | 169 | + }, | | 170 | + "markdownListEnumeration": { | | 171 | + "dark": "nord7", | | 172 | + "light": "nord7" | | 173 | + }, | | 174 | + "markdownImage": { | | 175 | + "dark": "nord9", | | 176 | + "light": "nord9" | | 177 | + }, | | 178 | + "markdownImageText": { | | 179 | + "dark": "nord7", | | 180 | + "light": "nord7" | | 181 | + }, | | 182 | + "markdownCodeBlock": { | | 183 | + "dark": "nord4", | | 184 | + "light": "nord0" | | 185 | + }, | | 186 | + "syntaxComment": { | | 187 | + "dark": "nord3", | | 188 | + "light": "nord3" | | 189 | + }, | | 190 | + "syntaxKeyword": { | | 191 | + "dark": "nord9", | | 192 | + "light": "nord9" | | 193 | + }, | | 194 | + "syntaxFunction": { | | 195 | + "dark": "nord8", | | 196 | + "light": "nord8" | | 197 | + }, | | 198 | + "syntaxVariable": { | | 199 | + "dark": "nord7", | | 200 | + "light": "nord7" | | 201 | + }, | | 202 | + "syntaxString": { | | 203 | + "dark": "nord14", | | 204 | + "light": "nord14" | | 205 | + }, | | 206 | + "syntaxNumber": { | | 207 | + "dark": "nord15", | | 208 | + "light": "nord15" | | 209 | + }, | | 210 | + "syntaxType": { | | 211 | + "dark": "nord7", | | 212 | + "light": "nord7" | | 213 | + }, | | 214 | + "syntaxOperator": { | | 215 | + "dark": "nord9", | | 216 | + "light": "nord9" | | 217 | + }, | | 218 | + "syntaxPunctuation": { | | 219 | + "dark": "nord4", | | 220 | + "light": "nord0" | | 221 | + } | | 222 | + } | | 223 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/context/theme.tsx +44-3Lines changed: 44 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { SyntaxStyle, RGBA, type TerminalColors } from "@opentui/core" | 2 | | -import { createMemo } from "solid-js" | | 2 | +import path from "path" | | 3 | +import { createEffect, createMemo, onMount } from "solid-js" | 3 | 4 | import { useSync } from "@tui/context/sync" | 4 | 5 | import { createSimpleContext } from "./helper" | 5 | 6 | import aura from "./theme/aura.json" with { type: "json" } | @@ -27,7 +28,9 @@ import vesper from "./theme/vesper.json" with { type: "json" } | 27 | 28 | import zenburn from "./theme/zenburn.json" with { type: "json" } | 28 | 29 | import { useKV } from "./kv" | 29 | 30 | import { useRenderer } from "@opentui/solid" | 30 | | -import { createStore } from "solid-js/store" | | 31 | +import { createStore, produce } from "solid-js/store" | | 32 | +import { Global } from "@/global" | | 33 | +import { Filesystem } from "@/util/filesystem" | 31 | 34 |
| 32 | 35 | type Theme = { | 33 | 36 | primary: RGBA | @@ -144,6 +147,17 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({ | 144 | 147 | themes: DEFAULT_THEMES, | 145 | 148 | mode: props.mode, | 146 | 149 | active: (sync.data.config.theme ?? kv.get("theme", "opencode")) as string, | | 150 | + ready: false, | | 151 | + }) | | 152 | + | | 153 | + createEffect(async () => { | | 154 | + const custom = await getCustomThemes() | | 155 | + setStore( | | 156 | + produce((draft) => { | | 157 | + Object.assign(draft.themes, custom) | | 158 | + draft.ready = true | | 159 | + }), | | 160 | + ) | 147 | 161 | }) | 148 | 162 |
| 149 | 163 | const renderer = useRenderer() | @@ -187,12 +201,39 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({ | 187 | 201 | kv.set("theme", theme) | 188 | 202 | }, | 189 | 203 | get ready() { | 190 | | - return sync.ready | | 204 | + return store.ready | 191 | 205 | }, | 192 | 206 | } | 193 | 207 | }, | 194 | 208 | }) | 195 | 209 |
| | 210 | +const CUSTOM_THEME_GLOB = new Bun.Glob("themes/*.json") | | 211 | +async function getCustomThemes() { | | 212 | + const directories = [ | | 213 | + Global.Path.config, | | 214 | + ...(await Array.fromAsync( | | 215 | + Filesystem.up({ | | 216 | + targets: [".opencode"], | | 217 | + start: process.cwd(), | | 218 | + }), | | 219 | + )), | | 220 | + ] | | 221 | + | | 222 | + const result: Record<string, ThemeJson> = {} | | 223 | + for (const dir of directories) { | | 224 | + for await (const item of CUSTOM_THEME_GLOB.scan({ | | 225 | + absolute: true, | | 226 | + followSymlinks: true, | | 227 | + dot: true, | | 228 | + cwd: dir, | | 229 | + })) { | | 230 | + const name = path.basename(item, ".json") | | 231 | + result[name] = await Bun.file(item).json() | | 232 | + } | | 233 | + } | | 234 | + return result | | 235 | +} | | 236 | + | 196 | 237 | function generateSystem(colors: TerminalColors, mode: "dark" | "light"): ThemeJson { | 197 | 238 | const bg = RGBA.fromHex(colors.defaultBackground ?? colors.palette[0]!) | 198 | 239 | const fg = RGBA.fromHex(colors.defaultForeground ?? colors.palette[7]!) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/server.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -163,6 +163,7 @@ export namespace Server { | 163 | 163 | return c.json(await Config.get()) | 164 | 164 | }, | 165 | 165 | ) | | 166 | + | 166 | 167 | .patch( | 167 | 168 | "/config", | 168 | 169 | describeRoute({ | |
Collapse file Copy file name to clipboardExpand all lines: packages/plugin/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | "typescript": "catalog:", | 25 | 25 | "@typescript/native-preview": "catalog:" | 26 | 26 | } | 27 | | -} | | 27 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/sdk/js/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | "publishConfig": { | 27 | 27 | "directory": "dist" | 28 | 28 | } | 29 | | -} | | 29 | +} |
|