-
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
Pretty printer library switch with ANSI compatibility #428
Conversation
Before:
After:
|
The idea behind the new style is it prefers compact display such as this:
But that if the length of the group should exceed the remaining space on the line, it should use structured multiline indented format:
Or combinations where it makes sense:
|
b3b15cb
to
ca02c8e
Compare
I created another version of this PR without the tracing annotations so it's clearer where the substantive differences are. |
Switching a pretty-printing library means that every downstream package has to adapt, because My understanding is that you have debugged the issue at hand. Is it possible to revert back to (I’m not a maintainer) |
I had a go yesterday, but it seems I pointed out tracing mainly to show that annotations are actually really convenient and could be used to annotate documents for richer output. I had a go at haskell/criterion#241 to show that in this case the necessary changes aren't too bad. To ease compatibility issues, we could minimise breaking changes. For the We could have an interim release where we make changes to |
What specifically do annotations buy us in case of
Yes, indeed, it is usually possible to migrate between pretty-printing libraries. But nevertheless it means that downstream dependencies must make necessary amends and releases, and pre-existing packages must be revised with
I think that more re-exports of this sort could pose even bigger compatibility issues in a long term. Imagine that some combinator is changed, deprecated or removed from |
@Bodigrim It seems that I think it only makes sense for the community to start switching to the |
Thanks for the PRs John. It's always great to have people put time into optparse-applicative. There are a couple of orthogonal points here, @Bodigrim's opinion is well warranted in my view. It's very important to me that optparse is API stable as a lot of libraries and programs depend on it both in the open source world and I imagine commercially as well (breaking peoples' builds for their choice of CLI library is a bit rich). So the questions are:
After the original issue mentioning the prettyprinter library, I did also make a branch to see what it would be like, but overall, my impression was that it's probably not worth the switch. ansi-wl-pprint is It would probably make a coloured renderer a bit easier and more declaritive if that was a direction we decided to take, but in reality if we wanted coloured output we could do that already. With regards to the actual rendering changes: I'm quite sure we should rethink how we do the hang when the program name and subcommand names are long as squashing the text into the side really does make it ugly. Starting them fresh on a new line with an indent really would be an improvement. I've been considering how it can be done without expanding the number of preference modifiers (again). The pretty printing is a bit of a balancing act. I do find what you've got more readable above, but it also seems a bit verbose – one of your examples above requires 5 lines for only 3 options. I'll run through the changes in detail when I get some more time. Edit: apparently it's not well maintained any more. |
I was thinking perhaps HTML help or man page support would be nice. It's not clear that annotations are strictly necessary to do this, but I'm thinking in these cases we could use annotations to delay some of the rendering to a later phase so we can re-use more code. |
I'm wondering if a good compromise would be to have instead of this:
something like this:
The rule would be if the list of options has no children, then the list will be rendered in compact form. In the above I'm guessing that it might actually end up like this:
|
Another perhaps out-there idea would be to use rainbow parens 😁 . |
@lehins thanks, I did not know that |
I'm cool for this to take a long as it needs, since we're currently on a fork. My hope is for the switch to happen at an appropriate and opportune time and to either improve the layout in the library or otherwise export some way for users to have more control of the layout externally. |
Out of curiosity I checked this branch against a standard Before:
After:
It's probably a matter of habit, but to be honest I like previous pretty-printing better. That's because I usually have a half-screen tall console window, so vertical space is quite precious. Ideally I'd prefer something even more condensed than currently, e. g.,
Maybe a choice of layout could be configurable to a certain extent?.. |
Thanks @Bodigrim for trying it out. Some configurability would be nice. There's also the possibility of choosing different layouts based on heuristics. For example if the parser is highly nested, it starts to get confusing so a structured layout is preferable, whereas if the parser is mostly linear, then compact is usually better. The came CLI tool may have the same multiple commands with different levels of complexity so a heuristic based layout selector would actually be quite nice. |
@Bodigrim I personally find this horrendous:
While this I personally find very eye appealing and much more readable as well:
So this is quite a subjective matter and I do agree that an option to configure would be awesome! In fact, if that could be a user supplied option this would be even better ;)
I find it hard to believe that this is a widespread setup, because monitors are all widescreen nowadays and splitting vertically is more efficient. That's why 80 char wrapping is still prevalent while coding |
I was considering, whether with We could even do a rainbow parens thing at the final stage of converting a docstream to text for those who want compact representation of highly nested options to still be somewhat readable. |
Thanks all for the input. There's no best way to pretty print options and arguments in all situations for all programs, and I think this thread is a bit too opinionated. It's not worth the stress. With regards to this PR: it's too big for me to merge as is, it changes the underlying dependency tree as well as changing the rendering in ways which are at the very least controversial. Here's my suggestion:
That sound cool? Huw |
Your suggestion is perfect. I have been working on ANSI colour support, which will be necessary to do the switch because |
3876479
to
2dba25e
Compare
I've removed all the code that is unrelated to the switch to |
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 second the switch to prettyprinter
.
I think the breakage caused by this is mitigated by the fact that optparse-applicative
exports Doc
and its combinators.
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.
Looks good from my perspective, I can still run bytestring
and text
test suite without cyclical dependency.
Is this PR good to be merged? Is there anything else that needs to be done? @HuwCampbell @andreasabel @Bodigrim |
CI hasn't run yet. @HuwCampbell , could you please hit the button? |
I've set this to run in CI. So my only real issue is that this doesn't really do that much. The focus here was to be as backwards compatible as possible which is good, but it's inlining a few functions which aren't exported, and really only sticking to what we can do at the moment. I have a little branch I'm working on as well (indeed I've had a look a few times), but I think if we want to make a breaking change it should offer more real advantages. My current thought is that we should probably use the annotations for a bit more than what is currently available, for example, optionally making the I know it's not super satisfying, but I don't want to push two big breaking changes to the pretty-printer. I'll set some time in my calendar for September to finish it off and figure out a nice API for user preference. |
2957cfb
to
12dd60f
Compare
I pushed a fix for older compilers:
|
12dd60f
to
6a9ff39
Compare
Any progress on moving to |
Any updates on this one? Are there still any concerns? Thanks |
Thank you for putting in this work, I used a bunch of the ideas in a recent release which achieves these goals. |
Thanks @HuwCampbell for putting together the changes for the new release. |
This PR modifiers the pretty printer to improve the structure of the output for readability.
Included in the change is the switch from
ansi-wl-pprint
toprettyprinter
. The switch allows for the use of annotations, which allows for tracing the structure of the document for ease of debugging.I'm looking for interest in merging improved formatting and switching to
prettyprinter
.