Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 90f05eb

Browse files
paste images in wsl using ctrl+v (anomalyco#4123)
Co-authored-by: GitHub Action <action@github.com>
1 parent b63b6d0 commit 90f05eb

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

packages/opencode/src/cli/cmd/tui/util/clipboard.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { $ } from "bun"
2-
import { platform } from "os"
2+
import { platform, release } from "os"
33
import clipboardy from "clipboardy"
44
import { lazy } from "../../../../util/lazy.js"
55
import { tmpdir } from "os"
@@ -29,6 +29,18 @@ export namespace Clipboard {
2929
}
3030
}
3131

32+
if (os === "win32" || release().includes("WSL")) {
33+
const script =
34+
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
35+
const base64 = await $`powershell.exe -command "${script}"`.nothrow().text()
36+
if (base64) {
37+
const imageBuffer = Buffer.from(base64.trim(), "base64")
38+
if (imageBuffer.length > 0) {
39+
return { data: imageBuffer.toString("base64"), mime: "image/png" }
40+
}
41+
}
42+
}
43+
3244
if (os === "linux") {
3345
const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer()
3446
if (wayland && wayland.byteLength > 0) {
@@ -40,18 +52,6 @@ export namespace Clipboard {
4052
}
4153
}
4254

43-
if (os === "win32") {
44-
const script =
45-
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
46-
const base64 = await $`powershell -command "${script}"`.nothrow().text()
47-
if (base64) {
48-
const imageBuffer = Buffer.from(base64.trim(), "base64")
49-
if (imageBuffer.length > 0) {
50-
return { data: imageBuffer.toString("base64"), mime: "image/png" }
51-
}
52-
}
53-
}
54-
5555
const text = await clipboardy.read().catch(() => {})
5656
if (text) {
5757
return { data: text, mime: "text/plain" }

0 commit comments

Comments
 (0)