Formatting

This commit is contained in:
2026-06-01 12:36:55 +02:00
parent b30243f674
commit c7e1d69e2d
37 changed files with 2187 additions and 1925 deletions
+24 -14
View File
@@ -13,30 +13,36 @@ const execAsync = promisify(exec);
// The command is a function that returns a promise that resolves to the result of the command.
const clipboardMethods = {
pbCopy: {
platform: (platform: string) => platform === 'darwin',
command: async (text: string) => execAsync(`printf '%s' '${text}' | pbcopy`),
platform: (platform: string) => platform === "darwin",
command: async (text: string) =>
execAsync(`printf '%s' '${text}' | pbcopy`),
},
xclip: {
platform: (platform: string) => platform === 'linux',
command: async (text: string) => execAsync(`printf '%s' '${text}' | xclip -selection clipboard`),
platform: (platform: string) => platform === "linux",
command: async (text: string) =>
execAsync(`printf '%s' '${text}' | xclip -selection clipboard`),
},
xsel: {
platform: (platform: string) => platform === 'linux',
command: async (text: string) => execAsync(`printf '%s' '${text}' | xsel --clipboard --input`),
platform: (platform: string) => platform === "linux",
command: async (text: string) =>
execAsync(`printf '%s' '${text}' | xsel --clipboard --input`),
},
ssh: {
platform: (platform: string) => platform === 'linux',
command: async (text: string) => process.stdout.write(`\x1b]52;c;${Buffer.from(text, 'utf-8').toString('base64')}\x07`),
platform: (platform: string) => platform === "linux",
command: async (text: string) =>
process.stdout.write(
`\x1b]52;c;${Buffer.from(text, "utf-8").toString("base64")}\x07`,
),
},
clip: {
platform: (platform: string) => platform === 'windows',
platform: (platform: string) => platform === "windows",
command: async (text: string) => execAsync(`echo|set /p="${text}" | clip`),
},
clipboardy: {
platform: (platform: string) => platform === 'windows',
platform: (platform: string) => platform === "windows",
command: async (text: string) => clipboardy.writeSync(text),
},
}
};
/**
* Attempts to copy text to clipboard using multiple methods.
@@ -51,7 +57,9 @@ export async function copyToClipboard(text: string): Promise<void> {
// Escape the text for shell commands
const escapedText = text.replace(/'/g, "'\\''");
const availableMethods = Object.values(clipboardMethods).filter(method => method.platform(platform));
const availableMethods = Object.values(clipboardMethods).filter((method) =>
method.platform(platform),
);
const errors: Error[] = [];
@@ -63,7 +71,7 @@ export async function copyToClipboard(text: string): Promise<void> {
continue;
}
return;
} catch(error) {
} catch (error) {
if (error instanceof Error) {
errors.push(error);
}
@@ -71,5 +79,7 @@ export async function copyToClipboard(text: string): Promise<void> {
}
// All methods failed
throw new Error(`Clipboard not available. ${errors.map(error => error.message).join('\n')}`);
throw new Error(
`Clipboard not available. ${errors.map((error) => error.message).join("\n")}`,
);
}
+1 -2
View File
@@ -160,8 +160,7 @@ export function listDirectoryEntries(
entries: [...entries, ...directories, ...files],
};
} catch (error) {
const message =
error instanceof Error ? error.message : String(error);
const message = error instanceof Error ? error.message : String(error);
return {
entries: [],
error: `Unable to read directory: ${message}`,