Skip to content

Commit 7a9290d

Browse files
authored
tui: show exit message banner (#11733)
1 parent cfbe9d3 commit 7a9290d

2 files changed

Lines changed: 53 additions & 11 deletions

File tree

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
11
import { useRenderer } from "@opentui/solid"
22
import { createSimpleContext } from "./helper"
33
import { FormatError, FormatUnknownError } from "@/cli/error"
4+
type Exit = ((reason?: unknown) => Promise<void>) & {
5+
message: {
6+
set: (value?: string) => () => void
7+
clear: () => void
8+
get: () => string | undefined
9+
}
10+
}
411

512
export const { use: useExit, provider: ExitProvider } = createSimpleContext({
613
name: "Exit",
714
init: (input: { onExit?: () => Promise<void> }) => {
815
const renderer = useRenderer()
9-
return async (reason?: any) => {
10-
// Reset window title before destroying renderer
11-
renderer.setTerminalTitle("")
12-
renderer.destroy()
13-
await input.onExit?.()
14-
if (reason) {
15-
const formatted = FormatError(reason) ?? FormatUnknownError(reason)
16-
if (formatted) {
17-
process.stderr.write(formatted + "\n")
16+
let message: string | undefined
17+
const store = {
18+
set: (value?: string) => {
19+
const prev = message
20+
message = value
21+
return () => {
22+
message = prev
1823
}
19-
}
20-
process.exit(0)
24+
},
25+
clear: () => {
26+
message = undefined
27+
},
28+
get: () => message,
2129
}
30+
const exit: Exit = Object.assign(
31+
async (reason?: unknown) => {
32+
// Reset window title before destroying renderer
33+
renderer.setTerminalTitle("")
34+
renderer.destroy()
35+
await input.onExit?.()
36+
if (reason) {
37+
const formatted = FormatError(reason) ?? FormatUnknownError(reason)
38+
if (formatted) {
39+
process.stderr.write(formatted + "\n")
40+
}
41+
}
42+
const text = store.get()
43+
if (text) process.stdout.write(text + "\n")
44+
process.exit(0)
45+
},
46+
{
47+
message: store,
48+
},
49+
)
50+
return exit
2251
},
2352
})

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { PermissionPrompt } from "./permission"
7777
import { QuestionPrompt } from "./question"
7878
import { DialogExportOptions } from "../../ui/dialog-export-options"
7979
import { formatTranscript } from "../../util/transcript"
80+
import { UI } from "@/cli/ui.ts"
8081

8182
addDefaultParsers(parsers.parsers)
8283

@@ -222,6 +223,18 @@ export function Session() {
222223

223224
// Allow exit when in child session (prompt is hidden)
224225
const exit = useExit()
226+
227+
createEffect(() => {
228+
return exit.message.set(
229+
[
230+
``,
231+
` █▀▀█ ${UI.Style.TEXT_DIM}${session()?.title}${UI.Style.TEXT_NORMAL}`,
232+
` █ █ ${UI.Style.TEXT_DIM}opencode -s ${session()?.id}${UI.Style.TEXT_NORMAL}`,
233+
` ▀▀▀▀ `,
234+
].join("\n"),
235+
)
236+
})
237+
225238
useKeyboard((evt) => {
226239
if (!session()?.parentID) return
227240
if (keybind.match("app_exit", evt)) {

0 commit comments

Comments
 (0)