Skip to content

Commit

Permalink
ability to specify minColumnWidth for Help.wrap (#1430)
Browse files Browse the repository at this point in the history
* ability to specify `minColumnWidth` for `Help.wrap`

* Added missing param in TypeScript for Help.wrap
  • Loading branch information
cravler committed Jan 11, 2021
1 parent d934573 commit fcc8988
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,17 @@ class Help {
* @param {string} str
* @param {number} width
* @param {number} indent
* @param {number} [minColumnWidth=40]
* @return {string}
*
*/

wrap(str, width, indent) {
wrap(str, width, indent, minColumnWidth = 40) {
// Detect manually wrapped and indented strings by searching for line breaks
// followed by multiple spaces/tabs.
if (str.match(/[\n]\s+/)) return str;
// Do not wrap if not enough room for a wrapped column of text (as could end up with a word per line).
const columnWidth = width - indent;
const minColumnWidth = 40;
if (columnWidth < minColumnWidth) return str;

const leadingStr = str.substr(0, indent);
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ declare namespace commander {
* Wrap the given string to width characters per line, with lines after the first indented.
* Do not wrap if insufficient room for wrapping, or string is manually formatted.
*/
wrap(str: string, width: number, indent: number): string;
wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;

/** Generate the built-in help text. */
formatHelp(cmd: Command, helper: Help): string;
Expand Down

0 comments on commit fcc8988

Please sign in to comment.