Skip to content

Commit 9c2220c

Browse files
authored
fix(toolkit): don't fail when terminal width is 0 (#2355)
On some CI systems the terminal width is reported as 0 (instead of "unknown"), which causes table formatting to fail. Enforce a minimum terminal width. Fixes #2253.
1 parent 9653ece commit 9c2220c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/@aws-cdk/cloudformation-diff/lib/format-table.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function buildColumnConfig(widths: number[] | undefined): { [index: number]: tab
4949
* fair share.
5050
*/
5151
function calculcateColumnWidths(rows: string[][], terminalWidth: number): number[] {
52+
// The terminal is sometimes reported to be 0. Also if the terminal is VERY narrow,
53+
// just assume a reasonable minimum size.
54+
terminalWidth = Math.max(terminalWidth, 40);
55+
5256
// use 'string-width' to not count ANSI chars as actual character width
5357
const columns = rows[0].map((_, i) => Math.max(...rows.map(row => stringWidth(row[i]))));
5458

@@ -108,4 +112,4 @@ const TABLE_BORDER_CHARACTERS = {
108112
joinLeft: tableColor('├'),
109113
joinRight: tableColor('┤'),
110114
joinJoin: tableColor('┼')
111-
};
115+
};

0 commit comments

Comments
 (0)