11import { createStore } from "solid-js/store"
22import { createMemo , For , Match , Show , Switch } from "solid-js"
33import { useKeyboard , useTerminalDimensions , type JSX } from "@opentui/solid"
4+ import { useKeybind } from "../../context/keybind"
45import { useTheme } from "../../context/theme"
56import type { PermissionRequest } from "@opencode-ai/sdk/v2"
67import { useSDK } from "../../context/sdk"
@@ -145,6 +146,7 @@ export function PermissionPrompt(props: { request: PermissionRequest }) {
145146 </ Switch >
146147 }
147148 options = { { confirm : "Confirm" , cancel : "Cancel" } }
149+ escapeKey = "cancel"
148150 onSelect = { ( option ) => {
149151 setStore ( "always" , false )
150152 if ( option === "cancel" ) return
@@ -199,7 +201,7 @@ export function PermissionPrompt(props: { request: PermissionRequest }) {
199201 < TextBody icon = "◇" title = { `Exa Code Search "` + ( input ( ) . query ?? "" ) + `"` } />
200202 </ Match >
201203 < Match when = { props . request . permission === "external_directory" } >
202- < TextBody icon = "⚠ " title = { `Access external directory ` + normalizePath ( input ( ) . path as string ) } />
204+ < TextBody icon = "← " title = { `Access external directory ` + normalizePath ( input ( ) . path as string ) } />
203205 </ Match >
204206 < Match when = { props . request . permission === "doom_loop" } >
205207 < TextBody icon = "⟳" title = "Continue after repeated failures" />
@@ -210,6 +212,7 @@ export function PermissionPrompt(props: { request: PermissionRequest }) {
210212 </ Switch >
211213 }
212214 options = { { once : "Allow once" , always : "Allow always" , reject : "Reject" } }
215+ escapeKey = "reject"
213216 onSelect = { ( option ) => {
214217 if ( option === "always" ) {
215218 setStore ( "always" , true )
@@ -230,9 +233,11 @@ function Prompt<const T extends Record<string, string>>(props: {
230233 title : string
231234 body : JSX . Element
232235 options : T
236+ escapeKey ?: keyof T
233237 onSelect : ( option : keyof T ) => void
234238} ) {
235239 const { theme } = useTheme ( )
240+ const keybind = useKeybind ( )
236241 const keys = Object . keys ( props . options ) as ( keyof T ) [ ]
237242 const [ store , setStore ] = createStore ( {
238243 selected : keys [ 0 ] ,
@@ -257,6 +262,11 @@ function Prompt<const T extends Record<string, string>>(props: {
257262 evt . preventDefault ( )
258263 props . onSelect ( store . selected )
259264 }
265+
266+ if ( props . escapeKey && ( evt . name === "escape" || keybind . match ( "app_exit" , evt ) ) ) {
267+ evt . preventDefault ( )
268+ props . onSelect ( props . escapeKey )
269+ }
260270 } )
261271
262272 return (
0 commit comments