-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Moderately improved dict printing #5706
Conversation
Could you post some sample output? That will make it much easier for people to bikeshed this :) |
Sure thing. It's pretty simplistic, but I think it's better than what we have now.
|
idx < 1 || println(io) | ||
print(" ") | ||
key = reprlimited(k) | ||
print(io, key) |
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.
Why not just replace these two lines with showlimited(io, key)
?
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.
Okay, nevermind. I see that you use the length of key
below.
+1. Seems like an improvement to me! |
Especially compared to the status quo, where the above example generates over 82k lines worth of output (on a TTY with 80 columns). It may seem contrived, but this was inspired by work with very large and highly-nested data-structures coming from MAT.jl and PLX.jl. |
It's not contrived at all. I suspect most of us have worked with exactly this sort of data. |
I've updated the PR to use As an aside, I've since hacked together a show-alternative that I specialized for a handful of datatypes. I found it immensely useful when digging into the MAT.jl format: see |
I love |
PR updated to simply use |
Bump. Having |
One-line-per-entry would be a lovely improvement. 👍 for this. |
I can do this better now. I'll rework it. |
Unicode is hard. There were a whole slew of issues in my original implementation. But I think I have something now that is really awesome. This now has a much more Julian style, aligns the
Or with some unicode:
Or the absolutely cruel:
|
This is an attempt at improving the situation for issue JuliaLang#1759. I've added slightly enhanced `summary`s with information about the number of k/v pairs for Associative and Key/ValueIterator types. This PR keeps the old behavior (mostly) as `showcompact`. I then added new functionality in `show` and `showlimited` for Associative and Key/ValueIterators, printing newlines as delimiters between key/value pairs. When output is limited, keys are truncated to the left third of the TTY screen and values are truncated at newlines or the screen edge, with the `=>` separators aligned.
Looks good, but I've spotted two details: on the first line, the text is cut too early, or the ending
|
The first issue is because there's no way for me to ask the values to show themselves in the space I have. Without revamping the whole show hierarchy, the best dict can do is arbitrarily truncate... at which point I don't know if there should be a trailing The second is a font issue. If your monospace font doesn't have those glyphs, a proportional font is substituted instead. Not much we can do there. On iOS that last |
I see, thanks! |
RFC: Moderately improved dict printing
Sorry for not testing earlier – this is the first thing I tried: julia> d = Dict()
Dict{Any,Any} with 0 entries
julia> d[1] = "foo"
"foo"
julia> d
Dict{Any,Any} with 1 entry:
… => "foo" So, minor tweaking is required for this. |
Should be fixed now. |
Argh, so sorry I missed that trivial case. Thanks for the quick fix, Jeff. |
This is a modest attempt at improving the situation for issue #1759. I've added
slightly enhanced
summary
s with information about the number of k/v pairs forAssociative and Key/ValueIterator types.
I'm still slightly confused by all the different methods used for show, but
this PR keeps the old behavior (mostly) as
showcompact
. I then added newfunctionality in
show
andshowlimited
, using newlines as delimiters betweenkey/value pairs. When output is limited, values are truncated at newlines or
the TTY screen edge and a limited number of pairs are printed.
The key and value iterators no longer spit out entire dictionaries when shown.
They instead show a limited
{}
array of the keys and values.