Skip to content
Merged
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/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,15 @@ export function Prompt(props: PromptProps) {
})
}

function setVimRegister(register: VimRegister, notify = false) {
async function setVimRegister(register: VimRegister, notify = false) {
if (!useSystemClipboardRegister()) {
vimState.setRegister(register)
return
}
clipboardRegister = register
if (!register) return
Clipboard.copy(register.text)

await Clipboard.copy(register.text)
.then(() => {
if (notify) toast.show({ message: "Copied to clipboard", variant: "info" })
})
Expand All @@ -606,8 +607,9 @@ export function Prompt(props: PromptProps) {

async function syncVimRegisterFromClipboard() {
if (!useSystemClipboardRegister()) return
const content = await Clipboard.read()
if (content?.mime !== "text/plain" || !content.data) {
const content = await Clipboard.read().catch(() => undefined)
if (!content) return
if (content.mime !== "text/plain" || !content.data) {
clipboardRegister = null
return
}
Expand Down
36 changes: 28 additions & 8 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,35 @@ export async function read(): Promise<Content | undefined> {
}

if (os === "linux") {
const wayland = await Process.run(["wl-paste", "-t", "image/png"], { nothrow: true })
if (wayland.stdout.byteLength > 0) {
return { data: Buffer.from(wayland.stdout).toString("base64"), mime: "image/png" }
const which = await getWhich()
const hasWlPaste = !!process.env["WAYLAND_DISPLAY"] && which("wl-paste")

if (hasWlPaste) {
const wayland = await Process.run(["wl-paste", "-t", "image/png"], { nothrow: true })
if (wayland.stdout.byteLength > 0) {
return { data: Buffer.from(wayland.stdout).toString("base64"), mime: "image/png" }
}
}
const x11 = await Process.run(["xclip", "-selection", "clipboard", "-t", "image/png", "-o"], {
nothrow: true,
})
if (x11.stdout.byteLength > 0) {
return { data: Buffer.from(x11.stdout).toString("base64"), mime: "image/png" }

if (!hasWlPaste) {
const x11 = await Process.run(["xclip", "-selection", "clipboard", "-t", "image/png", "-o"], {
nothrow: true,
})
if (x11.stdout.byteLength > 0) {
return { data: Buffer.from(x11.stdout).toString("base64"), mime: "image/png" }
}
}

// Read text via native tools before falling back to clipboardy
if (hasWlPaste) {
const text = await Process.text(["wl-paste", "--no-newline"], { nothrow: true })
if (text.text) return { data: text.text, mime: "text/plain" }
} else if (which("xclip")) {
const text = await Process.text(["xclip", "-selection", "clipboard", "-o"], { nothrow: true })
if (text.text) return { data: text.text, mime: "text/plain" }
} else if (which("xsel")) {
const text = await Process.text(["xsel", "--clipboard", "--output"], { nothrow: true })
if (text.text) return { data: text.text, mime: "text/plain" }
}
}

Expand Down
Loading