Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/prompt.copy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'node:assert/strict';

const test = (name: string, fn: () => void | Promise<void>) => {
Promise.resolve(fn()).then(() => {
console.log(`ok - ${name}`);
});
};

test('clipboard fallback keeps the original error message available to users', () => {
const message = 'Both xsel and fallback failed';
const output = `Clipboard unavailable. Copy the script manually.\n\n${message}`;

assert.equal(
output.includes('Clipboard unavailable. Copy the script manually.'),
true
);
assert.equal(output.includes(message), true);
});
14 changes: 12 additions & 2 deletions src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,18 @@ async function runOrReviseFlow(
label: '📋 ' + i18n.t('Copy'),
hint: i18n.t('Copy the generated script to your clipboard'),
value: async () => {
await clipboardy.write(script);
p.outro(i18n.t('Copied to clipboard!'));
try {
await clipboardy.write(script);
p.outro(i18n.t('Copied to clipboard!'));
} catch (error) {
const message =
error instanceof Error ? error.message : String(error);
p.outro(
`${i18n.t(
'Clipboard unavailable. Copy the script manually.'
)}\n\n${message}`
);
}
},
},
{
Expand Down