From 23171c5037ed487e7be0b561d05c458331f5ca7c Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 10 Nov 2022 15:50:52 -0800 Subject: [PATCH] chore: support narrow terminal windows for messages (#18714) This patch starts using a message box that's not really a box and thus is better behaving on a narrow-width terminals. Before: image After: image Signed-off-by: Andrey Lushnikov Co-authored-by: Dmitry Gozman --- packages/playwright-core/src/utils/index.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/playwright-core/src/utils/index.ts b/packages/playwright-core/src/utils/index.ts index a84512a92d..f388abbdca 100644 --- a/packages/playwright-core/src/utils/index.ts +++ b/packages/playwright-core/src/utils/index.ts @@ -191,12 +191,10 @@ export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL export function wrapInASCIIBox(text: string, padding = 0): string { const lines = text.split('\n'); - const maxLength = Math.max(...lines.map(line => line.length)); - return [ - '╔' + '═'.repeat(maxLength + padding * 2) + '╗', - ...lines.map(line => '║' + ' '.repeat(padding) + line + ' '.repeat(maxLength - line.length + padding) + '║'), - '╚' + '═'.repeat(maxLength + padding * 2) + '╝', - ].join('\n'); + const maxLineLength = Math.max(...lines.map(line => line.length)); + const separatorLength = process.stdout.columns || maxLineLength; + const separator = '═'.repeat(separatorLength); + return [separator, ...lines, separator, ''].join('\n'); } export function isFilePayload(value: any): boolean {