diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/bytes.ts | 5 | ||||
| -rw-r--r-- | src/util/keycodes.ts | 8 | ||||
| -rw-r--r-- | src/util/time.ts | 16 | ||||
| -rw-r--r-- | src/util/truncate.ts | 6 |
4 files changed, 6 insertions, 29 deletions
diff --git a/src/util/bytes.ts b/src/util/bytes.ts deleted file mode 100644 index 43ad49c..0000000 --- a/src/util/bytes.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const formatBytes = (n: number): string => { - if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`; - if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`; - return `${n} B`; -}; diff --git a/src/util/keycodes.ts b/src/util/keycodes.ts deleted file mode 100644 index 68be059..0000000 --- a/src/util/keycodes.ts +++ /dev/null @@ -1,8 +0,0 @@ -const VIRTUAL_KEY_CODES: Readonly<Record<string, number>> = { - Enter: 13, Tab: 9, Backspace: 8, Escape: 27, Delete: 46, " ": 32, - ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, - Home: 36, End: 35, PageUp: 33, PageDown: 34, -}; - -export const virtualKeyCode = (key: string): number => - VIRTUAL_KEY_CODES[key] ?? (key.length === 1 ? key.charCodeAt(0) : 0); diff --git a/src/util/time.ts b/src/util/time.ts deleted file mode 100644 index ae751f8..0000000 --- a/src/util/time.ts +++ /dev/null @@ -1,16 +0,0 @@ -export const sleep = (ms: number, signal?: AbortSignal): Promise<void> => - new Promise((resolve, reject) => { - if (signal?.aborted) { - reject(signal.reason ?? new Error("aborted")); - return; - } - const onAbort = (): void => { - clearTimeout(timer); - reject(signal?.reason ?? new Error("aborted")); - }; - const timer = setTimeout(() => { - signal?.removeEventListener("abort", onAbort); - resolve(); - }, ms); - signal?.addEventListener("abort", onAbort, { once: true }); - }); diff --git a/src/util/truncate.ts b/src/util/truncate.ts index 2bf0600..7a1fa02 100644 --- a/src/util/truncate.ts +++ b/src/util/truncate.ts @@ -33,3 +33,9 @@ export const applyTruncation = async (output: string, prefix: string): Promise<T const text = `${t.content}\n\n[Output truncated: ${t.outputLines} of ${t.totalLines} lines (${formatSize(t.outputBytes)} of ${formatSize(t.totalBytes)}). ${formatSize(omitted)} omitted. Full output: ${file}]`; return { text, fullOutputPath: file, wasTruncated: true }; }; + +export const formatBytes = (n: number): string => { + if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`; + if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`; + return `${n} B`; +}; |
