diff --git a/lib/internal/print_help.js b/lib/internal/print_help.js index 9d146719734..00c8330daaa 100644 --- a/lib/internal/print_help.js +++ b/lib/internal/print_help.js @@ -69,6 +69,7 @@ function getArgDescription(type) { function format({ options, aliases = new Map(), firstColumn, secondColumn }) { let text = ''; + let maxFirstColumnUsed = 0; for (const [ name, { helpText, type, value } @@ -106,6 +107,7 @@ function format({ options, aliases = new Map(), firstColumn, secondColumn }) { } text += displayName; + maxFirstColumnUsed = Math.max(maxFirstColumnUsed, displayName.length); if (displayName.length >= firstColumn) text += '\n' + ' '.repeat(firstColumn); else @@ -115,16 +117,26 @@ function format({ options, aliases = new Map(), firstColumn, secondColumn }) { firstColumn).trimLeft() + '\n'; } + if (maxFirstColumnUsed < firstColumn - 4) { + // If we have more than 4 blank gap spaces, reduce first column width. + return format({ + options, + aliases, + firstColumn: maxFirstColumnUsed + 2, + secondColumn + }); + } + return text; } function print(stream) { const { options, aliases } = getOptions(); - // TODO(addaleax): Allow a bit of expansion depending on `stream.columns` - // if it is set. - const firstColumn = 28; - const secondColumn = 40; + // Use 75 % of the available width, and at least 70 characters. + const width = Math.max(70, (stream.columns || 0) * 0.75); + const firstColumn = Math.floor(width * 0.4); + const secondColumn = Math.floor(width * 0.57); options.set('-', { helpText: 'script read from stdin (default; ' + 'interactive mode if a tty)' });