Skip to content

Commit f42e1c6

Browse files
committed
tui: fix focus management and dialog interactions
1 parent f68374a commit f42e1c6

File tree

7 files changed

+12
-44
lines changed

7 files changed

+12
-44
lines changed

packages/opencode/script/publish.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ if (!Script.preview) {
125125
"build() {",
126126
` cd "opencode-\${pkgver}"`,
127127
` bun install`,
128-
" cd packages/tui",
129-
` CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=\${pkgver}" -o tui cmd/opencode/main.go`,
130-
" cd ../opencode",
131-
` bun build --define OPENCODE_TUI_PATH="'$(realpath ../tui/tui)'" --define OPENCODE_VERSION="'\${pkgver}'" --compile --target=bun-linux-x64 --outfile=opencode ./src/index.ts`,
128+
" cd ./packages/opencode",
129+
` OPENCODE_CHANNEL=latest OPENCODE_VERSION=${pkgver} bun run ./script/build.ts --single`,
132130
"}",
133131
"",
134132
"package() {",

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export function Prompt(props: PromptProps) {
134134
keybind: "input_submit",
135135
category: "Prompt",
136136
onSelect: (dialog) => {
137+
if (!input.focused) return
137138
submit()
138139
dialog.clear()
139140
},

packages/opencode/src/cli/cmd/tui/routes/home.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
import { Prompt, type PromptRef } from "@tui/component/prompt"
2-
import { createEffect, createMemo, Match, Show, Switch, type ParentProps } from "solid-js"
1+
import { Prompt } from "@tui/component/prompt"
2+
import { createMemo, Match, Show, Switch, type ParentProps } from "solid-js"
33
import { useTheme } from "@tui/context/theme"
44
import { useKeybind } from "../context/keybind"
55
import type { KeybindsConfig } from "@opencode-ai/sdk"
66
import { Logo } from "../component/logo"
77
import { Locale } from "@/util/locale"
88
import { useSync } from "../context/sync"
99
import { Toast } from "../ui/toast"
10-
import { useDialog } from "../ui/dialog"
1110

1211
export function Home() {
1312
const sync = useSync()
1413
const { theme } = useTheme()
15-
const dialog = useDialog()
1614
const mcpError = createMemo(() => {
1715
return Object.values(sync.data.mcp).some((x) => x.status === "failed")
1816
})
19-
let promptRef: PromptRef | undefined = undefined
20-
21-
createEffect(() => {
22-
dialog.allClosedEvent.listen(() => {
23-
promptRef?.focus()
24-
})
25-
})
2617

2718
const Hint = (
2819
<Show when={Object.keys(sync.data.mcp).length > 0}>
@@ -64,7 +55,7 @@ export function Home() {
6455
<HelpRow keybind="agent_cycle">Switch agent</HelpRow>
6556
</box>
6657
<box width="100%" maxWidth={75} zIndex={1000} paddingTop={1}>
67-
<Prompt hint={Hint} ref={(r) => (promptRef = r)} />
58+
<Prompt hint={Hint} />
6859
</box>
6960
<Toast />
7061
</box>

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ export function Session() {
112112
let prompt: PromptRef
113113
const keybind = useKeybind()
114114

115-
createEffect(() => {
116-
dialog.allClosedEvent.listen(() => {
117-
prompt.focus()
118-
})
119-
})
120-
121115
useKeyboard((evt) => {
122116
if (dialog.stack.length > 0) return
123117

packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
130130
if (evt.name === "return") {
131131
const option = selected()
132132
if (option) {
133-
evt.preventDefault()
133+
// evt.preventDefault()
134134
if (option.onSelect) option.onSelect(dialog)
135135
props.onSelect?.(option)
136136
}

packages/opencode/src/cli/cmd/tui/ui/dialog.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
2-
import {
3-
batch,
4-
createContext,
5-
createEffect,
6-
Show,
7-
useContext,
8-
type JSX,
9-
type ParentProps,
10-
} from "solid-js"
2+
import { batch, createContext, Show, useContext, type JSX, type ParentProps } from "solid-js"
113
import { useTheme } from "@tui/context/theme"
124
import { Renderable, RGBA } from "@opentui/core"
135
import { createStore } from "solid-js/store"
14-
import { createEventBus } from "@solid-primitives/event-bus"
156

167
export function Dialog(
178
props: ParentProps<{
@@ -59,7 +50,6 @@ function init() {
5950
}[],
6051
size: "medium" as "medium" | "large",
6152
})
62-
const allClosedEvent = createEventBus<void>()
6353

6454
useKeyboard((evt) => {
6555
if (evt.name === "escape" && store.stack.length > 0) {
@@ -90,12 +80,6 @@ function init() {
9080
}, 1)
9181
}
9282

93-
createEffect(() => {
94-
if (store.stack.length === 0) {
95-
allClosedEvent.emit()
96-
}
97-
})
98-
9983
return {
10084
clear() {
10185
for (const item of store.stack) {
@@ -108,7 +92,9 @@ function init() {
10892
refocus()
10993
},
11094
replace(input: any, onClose?: () => void) {
111-
if (store.stack.length === 0) focus = renderer.currentFocusedRenderable
95+
if (store.stack.length === 0) {
96+
focus = renderer.currentFocusedRenderable
97+
}
11298
for (const item of store.stack) {
11399
if (item.onClose) item.onClose()
114100
}
@@ -129,9 +115,6 @@ function init() {
129115
setSize(size: "medium" | "large") {
130116
setStore("size", size)
131117
},
132-
get allClosedEvent() {
133-
return allClosedEvent
134-
},
135118
}
136119
}
137120

packages/script/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const CHANNEL =
2020
(await $`git branch --show-current`.text().then((x) => x.trim()))
2121
const IS_PREVIEW = CHANNEL !== "latest"
2222
const VERSION = await (async () => {
23+
if (process.env["OPENCODE_VERSION"]) return process.env["OPENCODE_VERSION"]
2324
if (IS_PREVIEW)
2425
return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
2526
const version = await fetch("https://registry.npmjs.org/opencode-ai/latest")

0 commit comments

Comments
 (0)