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

Wrap help lines at term width #428

Closed
kbknapp opened this issue Feb 17, 2016 · 7 comments
Closed

Wrap help lines at term width #428

kbknapp opened this issue Feb 17, 2016 · 7 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations

Comments

@kbknapp
Copy link
Member

kbknapp commented Feb 17, 2016

No description provided.

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations P4: nice to have A-help Area: documentation, including docs.rs, readme, examples, etc... labels Feb 17, 2016
@mitsuhiko
Copy link
Contributor

I'm very interested in this. This is currently basically impossible to emulate manually and it makes long help texts very hard to read because when the term wraps, it does not align with the start of the message.

As an example from an app i have:

        --use-dsymutil         Invoke dsymutil on encountered macho binaries to extract
the symbols before uploading.  This requires the dsymutil binary to be available.

@kbknapp
Copy link
Member Author

kbknapp commented Feb 24, 2016

I have a working local stash of this feature. The downside is that's a naive implementation and doesn't wrap by word, i.e. some words get cut in the middle. I'm going to continue playing with this as I have some ideas to improve it and at least get it to wrap where it's aesthetically pleasing.

@mitsuhiko your example above will end up outputting:

        --use-dsymutil         Invoke dsymutil on encountered macho binaries to extract
                               the symbols before uploading.  This requires the dsymutil 
                               binary to be available.

@kbknapp
Copy link
Member Author

kbknapp commented Mar 8, 2016

Just an update, my free time has been almost non-existent, but I'm hoping to have this complete over the next few days. More updates to follow...

@kbknapp
Copy link
Member Author

kbknapp commented Mar 13, 2016

Finally, after some back to the drawing board moments I have this working in a whitespace respecting way (i.e. it doesn't cut words in the middle). I'm updating tests now, and should have a PR in tonight. Once merged I'll go ahead and put out 2.2.0.

kbknapp added a commit that referenced this issue Mar 14, 2016
By default `clap` now automatically wraps and aligns help strings to the
term width. i.e.

```
    -o, --option <opt>    some really long help
text that should be auto aligned but isn't righ
t now
```

Now looks like this:

```
    -o, --option <opt>    some really long help
                          text that should be
                          auto aligned but isn't
                          right now
```

The wrapping also respects words, and wraps at spaces so as to not cut
words in the middle.

This requires the `libc` dep which is enabled (by default) with the
`wrap_help` cargo feature flag.

Closes #428
@kbknapp
Copy link
Member Author

kbknapp commented Mar 14, 2016

PR is in, here's a screenshot of what the term wrapping looks like using some arbitrary test options and flags. Term width is 66:

screenshot

Edit:
There's also the option to place the text on the line following the option, flag, or argument indented once (a la, some getopts/docopt style formatting for long help strings). This could also be applied per argument, or application/command wide.

@sru
Copy link
Contributor

sru commented Mar 14, 2016

An aside, what font is that?

@kbknapp
Copy link
Member Author

kbknapp commented Mar 14, 2016

Inconsolata, I love 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

3 participants