MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / readClipboardText

Function readClipboardText

cli/src/utils/clipboard-image.ts:560–587  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

558 * Read text from clipboard. Returns null if reading fails.
559 */
560export function readClipboardText(): string | null {
561 try {
562 const platform = process.platform
563 let result: ReturnType<typeof spawnSync>
564
565 switch (platform) {
566 case 'darwin':
567 result = spawnSync('pbpaste', [], { encoding: 'utf-8', timeout: 1000 })
568 break
569 case 'win32':
570 result = spawnSync('powershell', ['-Command', 'Get-Clipboard'], { encoding: 'utf-8', timeout: 1000 })
571 break
572 case 'linux':
573 result = spawnSync('xclip', ['-selection', 'clipboard', '-o'], { encoding: 'utf-8', timeout: 1000 })
574 break
575 default:
576 return null
577 }
578
579 if (result.status === 0 && result.stdout) {
580 const output = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf-8')
581 return output.replace(/\n+$/, '')
582 }
583 return null
584 } catch {
585 return null
586 }
587}
588

Callers 3

createTextPasteHandlerFunction · 0.90
createPasteHandlerFunction · 0.90
dispatchActionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected