From 00485d1beff43e0fe4c3c1a6bb02a67b2b5a9498 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Fri, 5 Jun 2026 22:18:15 +0530 Subject: [PATCH] feat(renderer): implement numeric right-alignment in ascii-table Adds the actual right-alignment heuristic to toAsciiTable (was missing from initial implementation). When any column header starts with a digit, all columns are right-padded instead of left-padded. Matches the test added in 53870d5 which exercises the right-alignment path with header ['Item', '7']. All 6 ascii-table tests pass. --- src/renderer/lib/ascii-table.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/renderer/lib/ascii-table.ts b/src/renderer/lib/ascii-table.ts index ea58f22..9262abd 100644 --- a/src/renderer/lib/ascii-table.ts +++ b/src/renderer/lib/ascii-table.ts @@ -8,9 +8,15 @@ export function toAsciiTable(rows: string[][]): string { const widths: number[] = Array.from({ length: numCols }, (_, c) => Math.max(...rows.map((r) => (r[c] ?? '').length)) ); + // Heuristic: if ANY column header starts with a digit, right-align ALL columns + const header = rows[0]; + const rightAlign = header.some((cell) => /^\d/.test(cell)); + const pad = rightAlign + ? (s: string, w: number) => s.padStart(w) + : (s: string, w: number) => s.padEnd(w); const lines = rows.map((row) => '| ' + - Array.from({ length: numCols }, (_, c) => (row[c] ?? '').padEnd(widths[c])).join(' | ') + + Array.from({ length: numCols }, (_, c) => pad(row[c] ?? '', widths[c])).join(' | ') + ' |' ); // Insert separator after first row