Skip to content
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

Automatically use NextLineHelp with long option names/values #597

Closed
joshtriplett opened this issue Jul 24, 2016 · 9 comments
Closed

Automatically use NextLineHelp with long option names/values #597

joshtriplett opened this issue Jul 24, 2016 · 9 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations
Milestone

Comments

@joshtriplett
Copy link
Contributor

Based on discussion in #587 .

Clap should limit the maximum width of the option name/value column, and automatically use NextLineHelp otherwise.

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations A-help Area: documentation, including docs.rs, readme, examples, etc... D: intermediate labels Jul 24, 2016
@kbknapp
Copy link
Member

kbknapp commented Aug 26, 2016

I think the base has been laid to do this, where the flags+spaces > longest word in the help string. This should be an easy add now. @joshtriplett is there another metric you'd use to determine when a flag/option is "too long" and should trigger use of the next line?

@kbknapp kbknapp added this to the 2.10.5 milestone Aug 26, 2016
@joshtriplett
Copy link
Contributor Author

joshtriplett commented Aug 27, 2016

@kbknapp In terms of heuristics, I'd suggest checking if the name of an option, its argument, and the needed whitespace would take up more than 25% of the terminal width. For an 80-character terminal, that'd be 20 characters, which seems reasonable.

Actually, somewhere around 20 characters is probably a reasonable upper limit in general, since even on a wider terminal you don't want an excessive amount of whitespace on other options caused by a single long option name. Perhaps "longer than 25% of the terminal width or 24 characters, whichever is smaller"?

@kbknapp
Copy link
Member

kbknapp commented Aug 27, 2016

@joshtriplett I did some checking just based on random Rust CLI, and on 80 column terminals quite a significant ratio of help lines would end up on the next line, even though the entirety of their help text fits. So I thought, perhaps only those who's help text is greater than 75% when the flags/options values, etc. is greater than 25%, which works, but still ends up (IMO) jumping to the next line too early.

So what I'd like to do, just as a start since we can change this later based on feedback and just aesthetics is to use 40% as the margin, and only when the help text exceeds the remaining 60%.

Perhaps even later we could make this editable 😜

@joshtriplett
Copy link
Contributor Author

@kbknapp The heuristic should definitely include "some help texts" (not just the current one) would wrap. 40% seems worth trying. And I'd rather see a sensible default heuristic than configurability. :)

@kbknapp
Copy link
Member

kbknapp commented Aug 28, 2016

@joshtriplett So I just finished implementing this, and ended up going with something far closer to what you originally stated. It moves the help text to the next line only if it doesn't fit, no matter the length of the flags/options/spaces/values. The exception to this is, is when the flags/options/spaces/values is less than 25%, at which point it just wraps normally as it would have. Of the tests I've run, this seems to be the least alerting and most natural.

i.e. at 70 width, the -c, --cafe (etc.) is greater than 25% and the help text is long, so this wraps to the next line.

ctest 0.1

USAGE:
    ctest [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --cafe <FILE>
        A coffeehouse, coffee shop, or café is an establishment which
        primarily serves hot coffee, related coffee beverages
        (e.g., café latte, cappuccino, espresso), tea, and other
        hot beverages. Some coffeehouses also serve cold beverages
        such as iced coffee and iced tea. Many cafés also serve
        some type of food, such as light snacks, muffins, or pastries.

@joshtriplett
Copy link
Contributor Author

That sounds good to me.

I'd still love to see the paragraph aligned with the help text of the other options, though. But that's a separate issue (#587).

@kbknapp
Copy link
Member

kbknapp commented Aug 28, 2016

Yeah, I'll have to play with it some more since those two paragraphs are aligned separately...so we'll see as I get more time to tinker! 👍

@joshtriplett
Copy link
Contributor Author

@kbknapp Because one is under FLAGS and the other is under OPTIONS? For a first pass, if it's easier, it'd be fine if all the FLAGS had a single indent level for help and all the OPTIONS had a single indent level for help, even if they didn't have the same one. I use UnifiedHelpMessage anyway. :)

kbknapp added a commit that referenced this issue Aug 28, 2016
…hen term width is determined to be too small, or help text is too long

Now `clap` will check if it should automatically place long help
messages on the next line after the flag/option. This is determined by
checking to see if the space taken by flag/option plus spaces and values
doesn't leave enough room for the entirety of the help message, with the
single exception of of if the flag/option/spaces/values is less than 25%
of the width.

Closes #597
@kbknapp
Copy link
Member

kbknapp commented Aug 28, 2016

Yeah they're determined independently...unless you use UnifiedHelpMessage 😉 But I think there's probably an ergonomic way to share that info and implement #587 easily. I'll just have to put some thought into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants