MCPcopy
hub / github.com/codeaashu/claude-code / copyAnsiToClipboard

Function copyAnsiToClipboard

src/utils/screenshotClipboard.ts:16–44  ·  view source on GitHub ↗
(
  ansiText: string,
  options?: AnsiToPngOptions,
)

Source from the content-addressed store, hash-verified

14 * no system fonts, so this works in every build (native and JS).
15 */
16export 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
46async function copyPngToClipboard(
47 pngPath: string,

Callers 1

handleScreenshotFunction · 0.85

Calls 5

mkdirFunction · 0.85
ansiToPngFunction · 0.85
copyPngToClipboardFunction · 0.85
unlinkFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected