Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/cli/src/ui/utils/TableRenderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ describe('TableRenderer', () => {
unmount();
});

it('handles extremely small terminal widths without crashing', async () => {
const headers = ['Col 1', 'Col 2'];
const rows = [['Data 1', 'Data 2']];
// This width is much smaller than the overhead, which could lead to negative column widths
const terminalWidth = 1;

const renderResult = await renderWithProviders(
<TableRenderer
headers={headers}
rows={rows}
terminalWidth={terminalWidth}
/>,
);
const { unmount } = renderResult;
// If it didn't throw RangeError: Invalid count value, the test passes
unmount();
});

it.each([
{
name: 'handles non-ASCII characters (emojis and Asian scripts) correctly',
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/ui/utils/TableRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ export const TableRenderer: React.FC<TableRendererProps> = ({
};

const char = chars[type];
const borderParts = adjustedWidths.map((w) => char.horizontal.repeat(w));
const borderParts = adjustedWidths.map((w) =>
char.horizontal.repeat(Math.max(0, w || 0)),
);
Comment thread
devr0306 marked this conversation as resolved.
const border = char.left + borderParts.join(char.middle) + char.right;

return <Text color={theme.border.default}>{border}</Text>;
Expand Down
Loading