File tree Expand file tree Collapse file tree
packages/opencode/src/cli/cmd/tui Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useRenderer } from "@opentui/solid"
22import { createSimpleContext } from "./helper"
33import { 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
512export 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} )
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ import { PermissionPrompt } from "./permission"
7777import { QuestionPrompt } from "./question"
7878import { DialogExportOptions } from "../../ui/dialog-export-options"
7979import { formatTranscript } from "../../util/transcript"
80+ import { UI } from "@/cli/ui.ts"
8081
8182addDefaultParsers ( 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 ) ) {
You can’t perform that action at this time.
0 commit comments