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
ability to specify minColumnWidth
for Help.wrap
#1430
Conversation
Do you have a situation when you want to be able to change minColumnWidth? Or suggesting it because it is currently a hard-coded value in the code? For historical interest, this was actually a parameter in the original PR! I removed it rather than try and add documentation for the parameter which we do not vary in the Commander code, as I struggled to differentiate it from the "width" parameter. The current variable name is the best I came up with at the time. |
maybe better to make like this? class Help {
formatHelp(cmd, helper) {
//...
function wrap(str, width, indent) {
// 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;
return return helper.wrap(str, width, indent);
}
function formatItem(term, description) {
if (description) {
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
return wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
}
return term;
};
// ...
}
} |
The reason for skipping the wrap at small sizes is that in the worst case can get a word per line, and unlike the fallback unwrapped output, this does not reflow as the terminal window is made wider as it is hard wrapped. e.g.
But being able to configure the cut-off is a reasonable request. Still thinking about that. |
I do not think this will be be used much, but it isn't a front-facing routine and this hopefully makes If you are still keen: add the TypeScript, and I'll add some comments when I merge it if it passes review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll add an explanation of the new parameter after merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Pull Request