()
| 558 | * Read text from clipboard. Returns null if reading fails. |
| 559 | */ |
| 560 | export 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 |
no outgoing calls
no test coverage detected