Skip to content

Commit

Permalink
fix(toolkit): don't fail when terminal width is 0
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 #2253.
  • Loading branch information
rix0rrr committed Apr 23, 2019
1 parent 50ba978 commit 790e7a8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 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 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

0 comments on commit 790e7a8

Please sign in to comment.