( ansiText: string, options?: AnsiToPngOptions, )
| 14 | * no system fonts, so this works in every build (native and JS). |
| 15 | */ |
| 16 | export async function copyAnsiToClipboard( |
| 17 | ansiText: string, |
| 18 | options?: AnsiToPngOptions, |
| 19 | ): Promise<{ success: boolean; message: string }> { |
| 20 | try { |
| 21 | const tempDir = join(tmpdir(), 'claude-code-screenshots') |
| 22 | await mkdir(tempDir, { recursive: true }) |
| 23 | |
| 24 | const pngPath = join(tempDir, `screenshot-${Date.now()}.png`) |
| 25 | const pngBuffer = ansiToPng(ansiText, options) |
| 26 | await writeFile(pngPath, pngBuffer) |
| 27 | |
| 28 | const result = await copyPngToClipboard(pngPath) |
| 29 | |
| 30 | try { |
| 31 | await unlink(pngPath) |
| 32 | } catch { |
| 33 | // Ignore cleanup errors |
| 34 | } |
| 35 | |
| 36 | return result |
| 37 | } catch (error) { |
| 38 | logError(error) |
| 39 | return { |
| 40 | success: false, |
| 41 | message: `Failed to copy screenshot: ${error instanceof Error ? error.message : 'Unknown error'}`, |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | async function copyPngToClipboard( |
| 47 | pngPath: string, |
no test coverage detected