summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHaris Gušić <[email protected]>2025-11-01 15:34:21 +0100
committerGitHub <[email protected]>2025-11-01 15:34:21 +0100
commit55787f2caa1051d1d4a8921a460ac8f7b1f3692d (patch)
tree74b894b868c1052ed5e8df2e00b2084b44a7af2f
parent7df61a74a091ee3629d866477c0259feb7b8051d (diff)
downloadopencode-55787f2caa1051d1d4a8921a460ac8f7b1f3692d.tar.gz
opencode-55787f2caa1051d1d4a8921a460ac8f7b1f3692d.zip
fix: tui: Handle Clipboard.copy errors properly (#3685)
-rw-r--r--packages/opencode/src/cli/cmd/tui/app.tsx3
-rw-r--r--packages/opencode/src/cli/cmd/tui/ui/toast.tsx14
-rw-r--r--packages/opencode/src/cli/cmd/tui/util/clipboard.ts4
3 files changed, 17 insertions, 4 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx
index 2427432ee..ab4750719 100644
--- a/packages/opencode/src/cli/cmd/tui/app.tsx
+++ b/packages/opencode/src/cli/cmd/tui/app.tsx
@@ -296,8 +296,9 @@ function App() {
/* @ts-expect-error */
renderer.writeOut(finalOsc52)
await Clipboard.copy(text)
+ .then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
+ .catch(toast.error)
renderer.clearSelection()
- toast.show({ message: "Copied to clipboard", variant: "info" })
}
}}
>
diff --git a/packages/opencode/src/cli/cmd/tui/ui/toast.tsx b/packages/opencode/src/cli/cmd/tui/ui/toast.tsx
index f742635e0..24d630c73 100644
--- a/packages/opencode/src/cli/cmd/tui/ui/toast.tsx
+++ b/packages/opencode/src/cli/cmd/tui/ui/toast.tsx
@@ -49,7 +49,7 @@ function init() {
let timeoutHandle: NodeJS.Timeout | null = null
- return {
+ const toast = {
show(options: ToastOptions) {
const parsedOptions = TuiEvent.ToastShow.properties.parse(options)
const { duration, ...currentToast } = parsedOptions
@@ -59,10 +59,22 @@ function init() {
setStore("currentToast", null)
}, duration).unref()
},
+ error: (err: any) => {
+ if (err instanceof Error)
+ return toast.show({
+ variant: "error",
+ message: err.message,
+ })
+ toast.show({
+ variant: "error",
+ message: "An unknown error has occurred",
+ })
+ },
get currentToast(): ToastOptions | null {
return store.currentToast
},
}
+ return toast
}
export type ToastContext = ReturnType<typeof init>
diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
index b0bd59ebe..6d4c07dea 100644
--- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
+++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
@@ -76,7 +76,7 @@ export namespace Clipboard {
const proc = Bun.spawn(["wl-copy"], { stdin: "pipe", stdout: "ignore", stderr: "ignore" })
proc.stdin.write(text)
proc.stdin.end()
- await proc.exited.catch(() => {})
+ await proc.exited
}
}
if (Bun.which("xclip")) {
@@ -117,7 +117,7 @@ export namespace Clipboard {
console.log("clipboard: no native support")
return async (text: string) => {
- await clipboardy.write(text).catch(() => {})
+ await clipboardy.write(text)
}
})