The printing of tables has been discussed recently, and every time I wonder how many different table-printing implementations, or tree-printing implementations are in the Julia ecosystem.
Here is how
As a package developer, each new type I write should ideally implement a
show method for each of these
MIME types. Plus
Atom, which sometimes needs special handling. And maybe Visual Studio…? That’s a lot of work! Even Base doesn’t bother;
Base.whos are pure ASCII, even in IJulia.
What I would like would be to just say “render this type as a table, with numbers below 0 in red”, then Julia, or some mystery package, would handle all the different MIME types to the best of that MIME type’s capabilities. Something like
using VisualElements # to be written! struct FamilyTreeNode person_name children end function VisualElements.renderas(node::FamilyTreeNode) # Display FamilyTreeNode objects as trees, and # highlight the people with no children. node_name = (isempty(node.children) ? VisualElements.emphasize(node.person_name) : node.person_name) VisualElements.tree(node_name, map(renderas, node.children)) end
In my ideal world,
renderas would be called from the fallback
show method in Base, but this isn’t strictly necessary.
VisualElements could offer a macro that implements all the
show methods for a particular type.
I’m sorry to say that I can’t make this happen, but with 1.0 nearing, I wanted to throw it out there in case it inspires someone to get the ball rolling.
show is nice, but it’s too low-level for most use cases.