Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolkit): don't fail when terminal width is 0 #2355

Merged
merged 2 commits into from
Apr 23, 2019
Merged
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
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('┼')
};
};