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
10 changes: 6 additions & 4 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ function App() {
title: "Open docs",
value: "docs.open",
onSelect: () => {
open("https://opencode.ai/docs").catch(() => {})
open("https://opencode.ai/docs").catch(() => { })
dialog.clear()
},
category: "System",
Expand All @@ -451,7 +451,7 @@ function App() {
title: "Open WebUI",
value: "webui.open",
onSelect: () => {
open(sdk.url).catch(() => {})
open(sdk.url).catch(() => { })
dialog.clear()
},
category: "System",
Expand Down Expand Up @@ -629,8 +629,10 @@ function App() {
renderer.writeOut(finalOsc52)
await Clipboard.copy(text)
.then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
.catch(toast.error)
renderer.clearSelection()
.catch((error) => {
toast.error(error)
renderer.clearSelection()
})
}
}}
>
Expand Down
26 changes: 19 additions & 7 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export namespace Clipboard {
}
}

const text = await clipboardy.read().catch(() => {})
const text = await clipboardy.read().catch(() => { })
if (text) {
return { data: text, mime: "text/plain" }
}
Expand All @@ -70,13 +70,15 @@ export namespace Clipboard {
}

if (os === "linux") {
if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-copy")) {
const isWayland = !!process.env["WAYLAND_DISPLAY"]
if (isWayland && Bun.which("wl-copy")) {
console.log("clipboard: using wl-copy")
return async (text: string) => {
const proc = Bun.spawn(["wl-copy"], { stdin: "pipe", stdout: "ignore", stderr: "ignore" })
proc.stdin.write(text)
proc.stdin.end()
await proc.exited.catch(() => {})
const code = await proc.exited.catch(() => 1)
if (code !== 0) throw new Error("wl-copy failed to copy to clipboard")
}
}
if (Bun.which("xclip")) {
Expand All @@ -89,7 +91,8 @@ export namespace Clipboard {
})
proc.stdin.write(text)
proc.stdin.end()
await proc.exited.catch(() => {})
const code = await proc.exited.catch(() => 1)
if (code !== 0) throw new Error("xclip failed to copy to clipboard")
}
}
if (Bun.which("xsel")) {
Expand All @@ -102,23 +105,32 @@ export namespace Clipboard {
})
proc.stdin.write(text)
proc.stdin.end()
await proc.exited.catch(() => {})
const code = await proc.exited.catch(() => 1)
if (code !== 0) throw new Error("xsel failed to copy to clipboard")
}
}

return async () => {
throw new Error(
isWayland
? "No clipboard tool found. Please install 'wl-clipboard'."
: "No clipboard tool found. Please install 'xclip' or 'xsel'.",
)
}
}

if (os === "win32") {
console.log("clipboard: using powershell")
return async (text: string) => {
// need to escape backticks because powershell uses them as escape code
const escaped = text.replace(/"/g, '""').replace(/`/g, "``")
await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.quiet()
}
}

console.log("clipboard: no native support")
return async (text: string) => {
await clipboardy.write(text).catch(() => {})
await clipboardy.write(text)
}
})

Expand Down