[Bug] Markdown tables with several columns render wider than the terminal, breaking their own borders
Description
parseMarkdownTable clamps every column to a minimum of TABLE_COLUMN_MIN_WIDTH (10 columns) but never re-checks that the resulting total still fits the terminal. With enough columns, the proportional share per column falls under 10 and every column gets bumped back up to the floor, so the table's real rendered width can end up well past the terminal width cli-table3 was told to respect.
Parent: #907
Steps to Reproduce
- Ask Nanocoder to produce a markdown table with 6+ columns (e.g. "compare these 5 frontend frameworks across name, license, stars, language, last updated, maintainer, bundle size, downloads").
- View the response on a normal 80-column terminal.
Expected Behavior
The table's box-drawing borders stay aligned and contained within the terminal width, same as a narrow table does.
Actual Behavior
The table overflows the terminal width. Box-drawing border characters no longer line up under each other, rows wrap unpredictably, and at least one row fell back to rendering completely unparsed raw markdown (| solidjs | MIT | 32000 | ... |) instead of going through the table renderer at all.
Recording
Root Cause
source/markdown-parser/table-parser.ts:66-77:
const borderWidth = numCols + 1; // vertical bars
const paddingWidth = numCols * 2; // 1 space on each side of each column
const availableWidth = terminalWidth - borderWidth - paddingWidth;
const totalContentWidth = contentWidths.reduce((a, b) => a + b, 0);
const colWidths = contentWidths.map(width =>
Math.max(
TABLE_COLUMN_MIN_WIDTH,
Math.floor((width / totalContentWidth) * availableWidth),
),
);
TABLE_COLUMN_MIN_WIDTH is 10 (source/constants.ts:88). Once enough columns each get floored to 10, sum(colWidths) + borderWidth + paddingWidth can exceed terminalWidth — e.g. 8 columns at 80 terminal columns: availableWidth = 80 - 9 - 16 = 55, but flooring every column to 10 makes the real width 8*10 + 9 + 16 = 105, 25 columns over budget. Nothing downstream rebalances or caps the total.
Suggested Fix
After computing colWidths, check whether their sum (+ border/padding overhead) exceeds availableWidth and, if so, shrink columns proportionally (or drop below the 10-column floor as a last resort) until the table fits or fall back to a non-table rendering (definition list style) when it structurally can't fit.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs on the latest
main
Hey @akramcodez, could you assign this to me ?
Picking this up - a fix will follow shortly.