-
Notifications
You must be signed in to change notification settings - Fork 23
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
std/prettyprints: pretty print any expression (including with cycles), customizable #385
Comments
This looks like a cool idea, but I don't see why it should be in the standard library. I think it would fit better as a nimble package (or at least in |
It exists as a package already; https://github.com/treeform/print, I don't think absorbing/obsoleting packages into the stdlib is healthy for the ecosystem at whole. We should simply ship a bunch of packages with the installation to give them exposure and use. |
|
I don't think it is a good idea to select any single implementation and add it to the fusion or stdlib, because there are so many elements that can be done differently, it would be quite hard to implement them all and have a reasonably simple solution. I also have a pretty-printer library that supports gitignore-style globs to ignore part of the objects, and global layout optimization - depending on the size of the object it might print it differently. I also plan to add support for int/string print style configuration (using gitignore globs as selectors as well), so I could select to print Do these features sound like something one might need? Yes, absolutely. I don't want to stare at the screen-worth of sequences, and for different reasons I do print a lot of them, so I put extra effort to layout things as compact as possible, but make it easier to view. In order to provide good layout, I implemented ad-hoc layouter for the first version and now writing v2 that would use https://research.google/pubs/pub44667/. Others might have different use cases, personal preferences, and in their case it might be completely pointless to put so much effort into this. For example, to me, it is kind of important that would be able to print things like |
@haxscramper I see, your prettyprint library does look great!
This is true, but there seems to be a need for easy pretty printing out there, so it might be worth discussing adding one of them to |
As a nim-newbie leveling up it's extremely unexpected that httpclient's Response isn't echo'able. treeform/print works well enough. But I agree with the sentiments from the OP. I really would expect such functionality to be in the standard library. I do OTOH agree completely that it should be kept as minimal as possible and avoid external large dependencies. Alas at my experience level I can't help with solving that issue. |
We can add something like treeform/pprint to the fusion. Full-featured pretty print implementation is very complicated, so I don't think like haxscramper/hmisc/pprint would be accepted anyway, and for simple use cases it is usually enough. Add some heuristics here and there to make sure long sequences/tables look good etc, and control whether output is colored or not This partially contradicts what I said earlier, but in the end treeform/print would be enough for the most, so I think it would be better to settle on an existing simple implementation rather than trying to discuss all potential requirements. But this would mean some things like HTML output should be left out. |
proposal
add a
std/prettyprints
module to allow pretty printing arbitrary expressionsdesign goal
As with std/jsonutils this should have:
$
stays simple (I'd still argue$
works for ref|ptr|pointer for all targets (c,cpp,js,vm) + other bugfixes Nim#14043 should be merged in some form or another but that's orhtogonal to this RFC)unlike dollars.nim, this is not a low-level module, and can have (at least optionally) heaver dependencies (eg tables.nim) for needed functionality and to simplify implementation
eg:
all overloads are
outplace
form and there's a singleinplace
form, just like in #191showDistinct
Hash[ByteAddress]
to mark already visited addresses and in case input is cyclicI've already implemented that in a private project with extensive options, so I know it's quite doable.
sample output
as html, with dynamically expandable nodes:
as a string, printed in terminal via
echo
links
$
works for ref|ptr|pointer for all targets (c,cpp,js,vm) + other bugfixes Nim#14043getTypeId
, from new: typetraits.getTypeId Nim#13305, as explained in new: typetraits.getTypeId Nim#13305 (comment)$
in scope)The text was updated successfully, but these errors were encountered: