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

optionally wrap help lines at less than terminal width #1469

Closed
wookietreiber opened this issue May 13, 2019 · 5 comments
Closed

optionally wrap help lines at less than terminal width #1469

wookietreiber opened this issue May 13, 2019 · 5 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Comments

@wookietreiber
Copy link

wookietreiber commented May 13, 2019

Maintainer's notes:

Workaround

let max_width = std::env::var("FOO_MAX_WIDTH")
    .and_then(|s| s.parse::<usize>().ok())
    .unwrap_or(100);
app
    .max_term_width(max_width)

Rust Version

  • rustc 1.34.1 (fc50f328b 2019-04-24)

Affected Version of clap

  • 2.33.0

Bug or Feature Request Summary

I have just browsed through quite some man pages (mostly git help cmd) and clap-generated long help outputs (bat, fd, some of my own tools). While doing that, I have noticed that man wraps paragraphs not at terminal width but less than that. This can be considered a follow-up to #428 and #451.

I think, I have noticed this because I have been looking at man pages for quite some time and, while the clap-generated long help output (--help) looks very similar to a man page (thank you for that, it's awesome!), it sometimes looked a bit weird (to me). I finally noticed what was bugging me and it is the wrapping.

In my opinion (yes, subjectively, I'm getting to that), it is more readable to wrap at less than terminal width. Maybe you feel the same way. Even if you do not feel the same way, you might (objectively) consider for clap-generated long help output to emulate the behavior of man pages in this regard.

It is subjective what looks best, to wrap at term width or to wrap at term width minus some value. Thus, objectively, this is not something that the CLI app developer should decide, but the user herself/himself. For this objective reason, I am suggesting to let the app user have the final say in this, not the developer as is done now. I suggest to add an environment variable that clap looks for, e.g. like in this ~/.bash_profile snippet:

# this if executes only if shell is interactive
if [[ $- == *i* ]]
then
  # if set, will override max_term_width
  # man for man page style
  # max for max term width
  # u64 for whatever unsigned integer you want
  export CLAP_WRAP_STYLE="[man|max|u64]"
fi

Note: I tested how man wraps with different terminal sizes. On standard terminal of 80 x 24 the wrapping is at column 78, so columns - 2 and with my usual terminal of 147 columns it's at columns - 4. I guess, they decide somehow. I haven't looked at their code yet.

@CreepySkeleton CreepySkeleton added A-help Area: documentation, including docs.rs, readme, examples, etc... T: new feature S-waiting-on-decision Status: Waiting on a go/no-go before implementing labels Feb 1, 2020
@pksunkara pksunkara added this to the 3.1 milestone Apr 9, 2020
@epage epage added C-enhancement Category: Raise on the bar on expectations and removed T: new feature labels Dec 8, 2021
@epage epage removed this from the 3.1 milestone Dec 9, 2021
@epage
Copy link
Member

epage commented Dec 9, 2021

How is this different than max_term_width requested in #653 and added in #654? Am I missing some context for how the two differ?

@epage epage added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-decision Status: Waiting on a go/no-go before implementing labels Dec 9, 2021
@pksunkara
Copy link
Member

From what I understood when the issue was created, they are asking some kind of runtime max width specifying capability.

@epage
Copy link
Member

epage commented Dec 9, 2021

You are right, I missed this part:

Thus, objectively, this is not something that the CLI app developer should decide, but the user herself/himself. For this objective reason, I am suggesting to let the app user have the final say in this, not the developer as is done now

If there is a standard env variable across apps, I can see reading it, like https://no-color.org/, otherwise, I think this is best left to the app developer to define and read the variable, setting max_term_width, like

let max_width = std::env::var("FOO_MAX_WIDTH")
    .and_then(|s| s.parse::<usize>().ok())
    .unwrap_or(100);
app
    .max_term_width(max_width)

The developer can read this and then apply it to other areas of their app as well.

Any reason for us to own this behavior in clap?

@pksunkara
Copy link
Member

Any reason for us to own this behavior in clap?

The only scenario I can think of is allow the user to specify the width via an arg. But this might be niche?

@epage
Copy link
Member

epage commented Dec 10, 2021

I've noted the way for users to directly do this in the Issue description. I think for now we should consider that the recommended solution. If there are concerns with this, feel free to speak up! It will help us know whether to re-evaluate.

@epage epage closed this as completed Dec 10, 2021
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 S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

No branches or pull requests

4 participants