tui: fix clipboard copy functionality in tmux sessions
Some checks are pending
format / format (push) Waiting to run
snapshot / publish (push) Waiting to run
test / test (push) Waiting to run

- Add proper tmux DCS passthrough wrapper for OSC52 sequences
- Users can now copy text to clipboard when running TUI inside tmux
- Previously clipboard copy would fail in SSH/tmux environments
This commit is contained in:
Dax Raad 2025-10-10 14:31:47 -04:00
parent f27cec5461
commit 8f3c87ffdb
2 changed files with 5 additions and 4 deletions

View file

@ -186,7 +186,11 @@ function App(props: { onExit: () => void }) {
onMouseUp={async () => {
const text = renderer.getSelection()?.getSelectedText()
if (text && text.length > 0) {
console.log("copying", text)
const base64 = Buffer.from(text).toString("base64")
const osc52 = `\x1b]52;c;${base64}\x07`
const finalOsc52 = process.env["TMUX"] ? `\x1bPtmux;\x1b${osc52}\x1b\\` : osc52
/* @ts-expect-error */
renderer.writeOut(finalOsc52)
await Clipboard.copy(text)
renderer.clearSelection()
}

View file

@ -112,9 +112,6 @@ export namespace Clipboard {
})
export async function copy(text: string): Promise<void> {
const base64 = Buffer.from(text).toString("base64")
const osc52 = `\x1b]52;c;${base64}\x07`
process.stdout.write(osc52)
await getCopyMethod()(text)
}
}