Skip to content

Commit 64bafce

Browse files
authored
restore direct osc52 (anomalyco#12071)
1 parent 5588453 commit 64bafce

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ function App() {
187187
const route = useRoute()
188188
const dimensions = useTerminalDimensions()
189189
const renderer = useRenderer()
190-
Clipboard.setRenderer(renderer)
191190
renderer.disableStdoutInterception()
192191
const dialog = useDialog()
193192
const local = useLocal()

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import { $ } from "bun"
2-
import type { CliRenderer } from "@opentui/core"
32
import { platform, release } from "os"
43
import clipboardy from "clipboardy"
54
import { lazy } from "../../../../util/lazy.js"
65
import { tmpdir } from "os"
76
import path from "path"
87

9-
const rendererRef = { current: undefined as CliRenderer | undefined }
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+
const passthrough = process.env["TMUX"] || process.env["STY"]
18+
const sequence = passthrough ? `\x1bPtmux;\x1b${osc52}\x1b\\` : osc52
19+
process.stdout.write(sequence)
20+
}
1021

1122
export namespace Clipboard {
1223
export interface Content {
1324
data: string
1425
mime: string
1526
}
1627

17-
export function setRenderer(renderer: CliRenderer | undefined): void {
18-
rendererRef.current = renderer
19-
}
20-
2128
export async function read(): Promise<Content | undefined> {
2229
const os = platform()
2330

@@ -146,12 +153,7 @@ export namespace Clipboard {
146153
})
147154

148155
export async function copy(text: string): Promise<void> {
149-
const renderer = rendererRef.current
150-
if (renderer) {
151-
// Try OSC52 but don't early return - always fall back to native method
152-
// OSC52 may report success but not actually work in all terminals
153-
renderer.copyToClipboardOSC52(text)
154-
}
156+
writeOsc52(text)
155157
await getCopyMethod()(text)
156158
}
157159
}

0 commit comments

Comments
 (0)