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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function DialogThemeList() {
const initial = theme.selected

onCleanup(() => {
if (!confirmed) theme.set(initial)
if (!confirmed) theme.preview(initial)
})

return (
Expand All @@ -26,7 +26,7 @@ export function DialogThemeList() {
options={options}
current={initial}
onMove={(opt) => {
theme.set(opt.value)
theme.preview(opt.value)
}}
onSelect={(opt) => {
theme.set(opt.value)
Expand All @@ -38,12 +38,12 @@ export function DialogThemeList() {
}}
onFilter={(query) => {
if (query.length === 0) {
theme.set(initial)
theme.preview(initial)
return
}

const first = ref.filtered[0]
if (first) theme.set(first.value)
if (first) theme.preview(first.value)
}}
/>
)
Expand Down
5 changes: 5 additions & 0 deletions packages/opencode/src/cli/cmd/tui/context/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
kv.set("theme", theme)
return true
},
preview(theme: string) {
if (!hasTheme(theme)) return false
setStore("active", theme)
return true
},
get ready() {
return store.ready
},
Expand Down
11 changes: 11 additions & 0 deletions packages/opencode/test/fixture/tui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type Opts = {
selected?: string
has?: HostPluginApi["theme"]["has"]
set?: HostPluginApi["theme"]["set"]
preview?: HostPluginApi["theme"]["preview"]
install?: HostPluginApi["theme"]["install"]
mode?: HostPluginApi["theme"]["mode"]
ready?: boolean
Expand Down Expand Up @@ -149,6 +150,13 @@ export function createTuiPluginApi(opts: Opts = {}): HostPluginApi {
selected = name
return true
})
const preview =
opts.theme?.preview ??
((name: string) => {
if (!has(name)) return false
selected = name
return true
})
const renderer: CliRenderer = opts.renderer ?? {
...Object.create(null),
once(this: CliRenderer) {
Expand Down Expand Up @@ -339,6 +347,9 @@ export function createTuiPluginApi(opts: Opts = {}): HostPluginApi {
set(name) {
return set(name)
},
preview(name) {
return preview(name)
},
async install(file) {
if (opts.theme?.install) return opts.theme.install(file)
throw new Error("base theme.install should not run")
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export type TuiTheme = {
readonly selected: string
has: (name: string) => boolean
set: (name: string) => boolean
preview: (name: string) => boolean
install: (jsonPath: string) => Promise<void>
mode: () => "dark" | "light"
readonly ready: boolean
Expand Down
Loading