Skip to content

Commit

Permalink
fix(toolkit): don't fail when terminal width is 0 (aws#2355)
Browse files Browse the repository at this point in the history
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 aws#2253.
  • Loading branch information
rix0rrr authored and piradeepk committed Apr 25, 2019
1 parent bcf5e96 commit 54408c9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@aws-cdk/cloudformation-diff/lib/format-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function buildColumnConfig(widths: number[] | undefined): { [index: number]: tab
* fair share.
*/
function calculcateColumnWidths(rows: string[][], terminalWidth: number): number[] {
// The terminal is sometimes reported to be 0. Also if the terminal is VERY narrow,
// just assume a reasonable minimum size.
terminalWidth = Math.max(terminalWidth, 40);

// use 'string-width' to not count ANSI chars as actual character width
const columns = rows[0].map((_, i) => Math.max(...rows.map(row => stringWidth(row[i]))));

Expand Down Expand Up @@ -108,4 +112,4 @@ const TABLE_BORDER_CHARACTERS = {
joinLeft: tableColor('├'),
joinRight: tableColor('┤'),
joinJoin: tableColor('┼')
};
};

0 comments on commit 54408c9

Please sign in to comment.