From 790e7a841a36611538cafefe949b5693b03b471d Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 23 Apr 2019 09:42:19 +0200 Subject: [PATCH] fix(toolkit): don't fail when terminal width is 0 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. --- packages/@aws-cdk/cloudformation-diff/lib/format-table.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/@aws-cdk/cloudformation-diff/lib/format-table.ts b/packages/@aws-cdk/cloudformation-diff/lib/format-table.ts index cd9a05c4b478f..4ccbcd910fe9f 100644 --- a/packages/@aws-cdk/cloudformation-diff/lib/format-table.ts +++ b/packages/@aws-cdk/cloudformation-diff/lib/format-table.ts @@ -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]))));