fix(tui): make mac copy use pbcopy

This commit is contained in:
kshitijk4poor 2026-04-19 13:54:18 +05:30 committed by kshitij
parent 1d0b94a1b9
commit e388910fe6
4 changed files with 104 additions and 7 deletions

View file

@ -1,4 +1,4 @@
import { execFile } from 'node:child_process'
import { execFile, spawn } from 'node:child_process'
import { promisify } from 'node:util'
const execFileAsync = promisify(execFile)
@ -26,3 +26,33 @@ export async function readClipboardText(
return null
}
}
/**
* Write plain text to the system clipboard.
*
* On macOS this uses `pbcopy`. On other platforms we intentionally return
* false for now; non-mac copy still falls back to OSC52.
*/
export async function writeClipboardText(
text: string,
platform: NodeJS.Platform = process.platform,
start: typeof spawn = spawn
): Promise<boolean> {
if (platform !== 'darwin') {
return false
}
try {
const ok = await new Promise<boolean>(resolve => {
const child = start('pbcopy', [], { stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true })
child.once('error', () => resolve(false))
child.once('close', code => resolve(code === 0))
child.stdin.end(text)
})
return ok
} catch {
return false
}
}