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.
This commit is contained in:
2026-06-05 22:18:15 +05:30
parent 24bb9aa9f5
commit 00485d1bef
+7 -1
View File
@@ -8,9 +8,15 @@ export function toAsciiTable(rows: string[][]): string {
const widths: number[] = Array.from({ length: numCols }, (_, c) => const widths: number[] = Array.from({ length: numCols }, (_, c) =>
Math.max(...rows.map((r) => (r[c] ?? '').length)) 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) => 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 // Insert separator after first row