-
Notifications
You must be signed in to change notification settings - Fork 116
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
Allow to tune behavior of the brief description renderer #494
Allow to tune behavior of the brief description renderer #494
Conversation
G'day, So if memory servers I'll have a proper look and think soon, I'm not too opposed to this if folks would find it useful, though to be honest I think the default layout is nicer. Cheers. |
Nice to meet you @HuwCampbell and looking forward to your review 😎 |
Hey @HuwCampbell, I hope you're doing good 👋 Did you have the time to look at this PR? |
G'day. Yes, I am doing quite well. My family has a new puppy, they're very time consuming (both my kids and the puppy). Honestly I'm a bit finicky about changes to the pretty printing because there's no one size that fits all. I just try to balance things as best I can to make our users' users experience as pleasant as possible. Personally, I think that pushing everything over to the right that far and having alternatives split over different lines like you've shown is quite undesirable and should be avoided. The printer takes quite a bit of care to keep alternatives on the same line if it can. (This is the functions That said, I'm not going to unequivocally say no to a simple customisation if it's called for. As far as this PR goes, I don't think this is quite the right thing. If I ever want to adjust said option it's a PVP breaking change right on the data type, and I try to do at most one a year at this stage. So I would prefer just one integer option on the level at which you prefer to reïndent. |
src/Options/Applicative/Builder.hs
Outdated
@@ -582,6 +583,9 @@ helpShowGlobals = PrefsMod $ \p -> p { prefHelpShowGlobal = True } | |||
helpIndent :: Int -> PrefsMod | |||
helpIndent w = PrefsMod $ \p -> p { prefTabulateFill = w } | |||
|
|||
-- | Set the pretty printer for brief help text. | |||
briefPrettyPrinter :: BriefPrettyPrinter -> PrefsMod | |||
briefPrettyPrinter bpp = PrefsMod $ \p -> p { prefBriefPP = bpp } |
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.
I think it would be better to do this differently, requiring the consumer of optparse to use the constructor and having it exported in types makes it a part of the "public API" which is a bit fragile; and it's not really in line with the other modifiers we have.
In my opinion it's better to instead have an option like:
briefHangPoint :: Int -> PrefsMod
which sets the location where the hang constructor kicks in (this is just 35
currently).
Now, when I mentioned that I thought the constructor was redundant, I was going off the definition of hangAtIfOver
being
hangAtIfOver :: Int -> Int -> Doc -> Doc
hangAtIfOver i j d =
column $ \k ->
if k <= j then
align d
else
linebreak <> ifAtRoot (indent i) d
so if one sets this to maxBound it is functionally identical to align
.
So I think just not having that type is just as good an option.
What do you think?
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.
Hey @HuwCampbell, I did the change and indeed it's simpler 👍
And I confirm that setting j
to maxBound
is indeed functionally equivalent to the previous design 👍
01383e4
to
1aad177
Compare
[--first-flag] | ||
[--second-flag] | ||
[--third-flag] | ||
[--fourth-flag] |
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.
The point of this test was to show the behaviour of the hang feature, so if you could delete the second commit I'd be much obliged.
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.
@HuwCampbell> I deleted the second commit and rebased on latest master
👍
Locally on my machine, all tests pass.
1aad177
to
2d25ad2
Compare
Ta |
Context
First of all, thank you @HuwCampbell for your work on
optparse-applicative
. We (at cardano-cli) are very happy users ofoptparse-applicative
!This PR allows to tune the behavior of the renderer of descriptions. An option is added that favors vertical alignment when displaying multiple flags, instead of maximizing the use of space on a single line.
The default behavior is unchanged and no change is imposed upon users. This PR solely make it possible for callers that prefer vertical alignment to do so.
Caveats
I am not super savvy about the different options that could be proposed. I have only proposed the existing behavior and the new one, which happen to yield very different results, as the change to the golden file of the changed test exemplifies:
We have many more examples at
cardano-cli
where we find this change beneficial in terms of readibility of the--help
message when there are many flags available. For example:Here is another one:
History
For the record, this is an improvement that originally comes from #428 and which we have maintained in this fork, but we now want to remove this fork, to shrink the spread in the Haskell ecosystem, and reduce maintenance burden.