Skip to content

Commit 79e831f

Browse files
committed
fix(tui): restore double Ctrl+C to exit functionality (anomalyco#247)
Re-add the tryExit() wrapper that shows a warning toast on first Ctrl+C and only exits on second press within 2 seconds. This prevents accidental exits when the prompt is empty.
1 parent 7f10655 commit 79e831f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • packages/opencode/src/cli/cmd/tui/component/prompt

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,22 @@ export function Prompt(props: PromptProps) {
668668
}
669669
const exit = useExit()
670670

671+
let lastExitAttempt = 0
672+
673+
async function tryExit() {
674+
const now = Date.now()
675+
if (now - lastExitAttempt < 2000) {
676+
await exit()
677+
return
678+
}
679+
lastExitAttempt = now
680+
toast.show({
681+
variant: "warning",
682+
message: "Press again to exit",
683+
duration: 2000,
684+
})
685+
}
686+
671687
function pasteText(text: string, virtualText: string) {
672688
const currentOffset = input.visualCursor.offset
673689
const extmarkStart = currentOffset
@@ -847,7 +863,7 @@ export function Prompt(props: PromptProps) {
847863
}
848864
if (keybind.match("app_exit", e)) {
849865
if (store.prompt.input === "") {
850-
await exit()
866+
await tryExit()
851867
// Don't preventDefault - let textarea potentially handle the event
852868
e.preventDefault()
853869
return

0 commit comments

Comments
 (0)