Skip to content

Commit 8e985e0

Browse files
Use opentui OSC52 clipboard (anomalyco#11718)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
1 parent a4d31b6 commit 8e985e0

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

bun.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/hashes.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"nodeModules": {
3-
"x86_64-linux": "sha256-06Otz3loT4vn0578VDxUqVudtzQvV7oM3EIzjZnsejo=",
4-
"aarch64-linux": "sha256-88Qai5RkSenCZkakOg52b6xU2ok+h/Ns4/5L3+55sFY=",
5-
"aarch64-darwin": "sha256-x8dgCF0CJBWi2dZLDHMGdlTqys1X755ok0PM6x0HAGo=",
6-
"x86_64-darwin": "sha256-FkLDqorfIfOw+tB7SW5vgyhOIoI0IV9lqPW1iEmvUiI="
3+
"x86_64-linux": "sha256-aRFzPzgu32XgNSk8S2z4glTlgHqEmOLZHlBQSIYIMvY=",
4+
"aarch64-linux": "sha256-aCZLkmRrCa0bli0jgsaLcC5GlZdjQPbb6xD6Fc03eX8=",
5+
"aarch64-darwin": "sha256-oZOOR6k8MmabNVDQNY5ywR06rRycdnXZL+gUucKSQ+g=",
6+
"x86_64-darwin": "sha256-LXIcLnjn+1eTFWIsQ9W0U2orGm59P/L470O0KFFkRHg="
77
}
88
}

packages/opencode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
"@opencode-ai/sdk": "workspace:*",
8383
"@opencode-ai/util": "workspace:*",
8484
"@openrouter/ai-sdk-provider": "1.5.4",
85-
"@opentui/core": "0.1.75",
86-
"@opentui/solid": "0.1.75",
85+
"@opentui/core": "0.1.76",
86+
"@opentui/solid": "0.1.76",
8787
"@parcel/watcher": "2.5.1",
8888
"@pierre/diffs": "catalog:",
8989
"@solid-primitives/event-bus": "1.1.2",

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ function App() {
186186
const route = useRoute()
187187
const dimensions = useTerminalDimensions()
188188
const renderer = useRenderer()
189+
Clipboard.setRenderer(renderer)
189190
renderer.disableStdoutInterception()
190191
const dialog = useDialog()
191192
const local = useLocal()

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
import { $ } from "bun"
2+
import type { CliRenderer } from "@opentui/core"
23
import { platform, release } from "os"
34
import clipboardy from "clipboardy"
45
import { lazy } from "../../../../util/lazy.js"
56
import { tmpdir } from "os"
67
import path from "path"
78

8-
/**
9-
* Writes text to clipboard via OSC 52 escape sequence.
10-
* This allows clipboard operations to work over SSH by having
11-
* the terminal emulator handle the clipboard locally.
12-
*/
13-
function writeOsc52(text: string): void {
14-
if (!process.stdout.isTTY) return
15-
const base64 = Buffer.from(text).toString("base64")
16-
const osc52 = `\x1b]52;c;${base64}\x07`
17-
// tmux and screen require DCS passthrough wrapping
18-
const passthrough = process.env["TMUX"] || process.env["STY"]
19-
const sequence = passthrough ? `\x1bPtmux;\x1b${osc52}\x1b\\` : osc52
20-
process.stdout.write(sequence)
21-
}
9+
const rendererRef = { current: undefined as CliRenderer | undefined }
2210

2311
export namespace Clipboard {
2412
export interface Content {
2513
data: string
2614
mime: string
2715
}
2816

17+
export function setRenderer(renderer: CliRenderer | undefined): void {
18+
rendererRef.current = renderer
19+
}
20+
2921
export async function read(): Promise<Content | undefined> {
3022
const os = platform()
3123

@@ -154,7 +146,11 @@ export namespace Clipboard {
154146
})
155147

156148
export async function copy(text: string): Promise<void> {
157-
writeOsc52(text)
149+
const renderer = rendererRef.current
150+
if (renderer) {
151+
const copied = renderer.copyToClipboardOSC52(text)
152+
if (copied) return
153+
}
158154
await getCopyMethod()(text)
159155
}
160156
}

0 commit comments

Comments
 (0)