* refactor(tui): group source files by feature * refactor(tui): split app and gateway responsibilities
19 lines
666 B
TypeScript
19 lines
666 B
TypeScript
export async function copyWithSystemClipboard(text: string): Promise<void> {
|
|
const commands = process.platform === "darwin"
|
|
? [["pbcopy"]]
|
|
: process.platform === "win32"
|
|
? [["clip.exe"]]
|
|
: [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"]]
|
|
for (const command of commands) {
|
|
try {
|
|
const child = Bun.spawn(command, { stdin: "pipe", stdout: "ignore", stderr: "ignore" })
|
|
child.stdin.write(text)
|
|
child.stdin.end()
|
|
if (await child.exited === 0) return
|
|
} catch {
|
|
// Try the next platform clipboard provider.
|
|
}
|
|
}
|
|
throw new Error("no clipboard provider available")
|
|
}
|