Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ function ErrorComponent(props: {
renderer.destroy()
win32FlushInputBuffer()
await props.onExit()
setTimeout(() => process.exit(0), 100)
}

useKeyboard((evt) => {
Expand Down
19 changes: 16 additions & 3 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function Prompt(props: PromptProps) {
mode: "normal" | "shell"
extmarkToPartIndex: Map<number, number>
interrupt: number
appExitArmed: number
placeholder: number
}>({
placeholder: Math.floor(Math.random() * PLACEHOLDERS.length),
Expand All @@ -135,6 +136,7 @@ export function Prompt(props: PromptProps) {
mode: "normal",
extmarkToPartIndex: new Map(),
interrupt: 0,
appExitArmed: 0,
})

createEffect(
Expand Down Expand Up @@ -865,8 +867,17 @@ export function Prompt(props: PromptProps) {
}
if (keybind.match("app_exit", e)) {
if (store.prompt.input === "") {
await exit()
// Don't preventDefault - let textarea potentially handle the event
const now = Date.now()
if (now - store.appExitArmed < 2000) {
await exit()
} else {
setStore("appExitArmed", now)
toast.show({
message: "Press Ctrl+C again to exit",
variant: "warning",
duration: 2000,
})
}
e.preventDefault()
return
}
Expand Down Expand Up @@ -967,7 +978,9 @@ export function Prompt(props: PromptProps) {
!sync.data.config.experimental?.disable_paste_summary
) {
event.preventDefault()
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
// Temporarily insert text directly without extmark to avoid the "can not paste certain string" bug
// which causes UI corruption and data loss on multi-line text
input.insertText(pastedContent)
return
}

Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/tui/context/exit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const { use: useExit, provider: ExitProvider } = createSimpleContext({
const text = store.get()
if (text) process.stdout.write(text + "\n")
await input.onExit?.()
setTimeout(() => process.exit(0), 100)
},
{
message: store,
Expand Down
5 changes: 5 additions & 0 deletions packages/opencode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ process.on("uncaughtException", (e) => {
})
})

process.on("SIGHUP", () => {
Log.Default.info("SIGHUP received, exiting...")
process.exit(0)
})

let cli = yargs(hideBin(process.argv))
.parserConfiguration({ "populate--": true })
.scriptName("opencode")
Expand Down
Loading