diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index e40f979a3..963d05445 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -20,33 +20,31 @@ import { Home } from "@tui/routes/home" import { Session } from "@tui/routes/session" import { PromptHistoryProvider } from "./component/prompt/history" import { DialogAlert } from "./ui/dialog-alert" +import { ExitProvider } from "./context/exit" export async function tui(input: { url: string; onExit?: () => Promise }) { await render( () => { return ( - - - - - - - - - { - await input.onExit?.() - process.exit(0) - }} - /> - - - - - - - - + + + + + + + + + + + + + + + + + + + ) }, { @@ -58,7 +56,7 @@ export async function tui(input: { url: string; onExit?: () => Promise }) ) } -function App(props: { onExit: () => void }) { +function App() { const route = useRoute() const dimensions = useTerminalDimensions() const renderer = useRenderer() @@ -86,10 +84,6 @@ function App(props: { onExit: () => void }) { renderer.console.toggle() return } - if (keybind.match("app_exit", evt)) { - renderer.destroy() - props.onExit() - } }) createEffect(() => { diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx index 6e1b6d63d..dbba84d92 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx @@ -32,6 +32,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create return { move(direction: 1 | -1) { + const prev = store.index setStore( produce((draft) => { const next = store.index + direction @@ -40,7 +41,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create draft.index = next }), ) - if (store.index === 0) + if (prev !== 0 && store.index === 0) return { input: "", parts: [], diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index 453004c30..dceaa2cd8 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -15,6 +15,7 @@ import { iife } from "@/util/iife" import { useCommandDialog } from "../dialog-command" import { useRenderer } from "@opentui/solid" import { Editor } from "@tui/util/editor" +import { useExit } from "../../context/exit" export type PromptProps = { sessionID?: string @@ -197,6 +198,7 @@ export function Prompt(props: PromptProps) { }) }, 50) } + const exit = useExit() return ( <> @@ -260,6 +262,17 @@ export function Prompt(props: PromptProps) { e.preventDefault() return } + if (keybind.match("input_clear", e) && store.prompt.input !== "") { + setStore("prompt", { + input: "", + parts: [], + }) + return + } + if (keybind.match("app_exit", e)) { + await exit() + return + } if (e.name === "!" && input.cursorPosition === 0) { setStore("mode", "shell") e.preventDefault() diff --git a/packages/opencode/src/cli/cmd/tui/context/exit.tsx b/packages/opencode/src/cli/cmd/tui/context/exit.tsx new file mode 100644 index 000000000..7d7feaa28 --- /dev/null +++ b/packages/opencode/src/cli/cmd/tui/context/exit.tsx @@ -0,0 +1,14 @@ +import { useRenderer } from "@opentui/solid" +import { createSimpleContext } from "./helper" + +export const { use: useExit, provider: ExitProvider } = createSimpleContext({ + name: "Exit", + init: (input: { onExit?: () => Promise }) => { + const renderer = useRenderer() + return async () => { + renderer.destroy() + await input.onExit?.() + process.exit(0) + } + }, +})