fix(artifact): use setClipboard instead of pbcopy for cross-platform support

This commit is contained in:
claude-code-best
2026-06-20 16:58:59 +08:00
parent 8fc21f9f9a
commit 1c29b571c5

View File

@@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import { Box, Text, useInput } from '@anthropic/ink'; import { Box, Text, setClipboard, useInput } from '@anthropic/ink';
import type { ArtifactInfo } from './scanner.js'; import type { ArtifactInfo } from './scanner.js';
import { openBrowser } from 'src/utils/browser.js'; import { openBrowser } from 'src/utils/browser.js';
@@ -35,7 +35,9 @@ export function ArtifactsMenu({ artifacts, onExit }: Props): React.ReactElement
if (input === 'c') { if (input === 'c') {
const target = artifacts[selected]; const target = artifacts[selected];
if (target.url) { if (target.url) {
copyToClipboard(target.url); void setClipboard(target.url).then(raw => {
if (raw) process.stdout.write(raw);
});
} }
} }
}); });
@@ -90,15 +92,3 @@ function ArtifactRow({ artifact, isSelected }: { artifact: ArtifactInfo; isSelec
</Box> </Box>
); );
} }
// macOS-only clipboard via pbcopy. The CLI is primarily macOS-targeted; on
// other platforms this is a no-op (URL is still rendered above for the user
// to select and copy manually).
function copyToClipboard(text: string): void {
try {
const { spawnSync } = require('node:child_process') as typeof import('node:child_process');
spawnSync('pbcopy', [], { input: text });
} catch {
// best-effort
}
}