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:
<img width="744" alt="image"
src="https://user-images.githubusercontent.com/746130/201216551-abbac0f8-71b4-413f-9f4e-159c7123ef3d.png">

After:
<img width="745" alt="image"
src="https://user-images.githubusercontent.com/746130/201216504-25257727-06c8-4ae9-8557-a2d937b7ca0b.png">

Signed-off-by: Andrey Lushnikov <aslushnikov@gmail.com>
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
This commit is contained in:
Andrey Lushnikov 2022-11-10 15:50:52 -08:00 committed by GitHub
parent db826c9c8c
commit 23171c5037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {