mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
fix(tui): make mac copy use pbcopy
This commit is contained in:
parent
1d0b94a1b9
commit
e388910fe6
4 changed files with 104 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue