[ANN] GarishPrint.jl - (Yet another) Pretty Printing your own julia objects!

I’m excited to announce a new package to make the types defined by your own easily colorful and structural, despite of the implementation itself, this package is extremely easy to use, you only need to replace your print function with pprint function exported by this package, and that’s it.

This functionality was originally inside Configurations with some ugly hacks, I rewrite the whole printing mechanism to make things better and easier to read.

There have been two other pretty printing packages in Julia which is PrettyPrint
and PrettyPrinting, but before I start talking about the boring implementation details, let’s have a fight!

TL;DR

just check this example

struct ABC{T1, T2, T3}
    hee::T1
    haa::T2
    hoo::T3
end

struct Example{T1, T2}
    field_a::T1
    field_b::T2
    abc::ABC
end

x = Example(
    Dict(
        "a"=>Example(
            [1, 2, 3],
            2.0,
            ABC(1, 2.0im, 3.12f0),
        ),
        "str" => Set([1, 2, 3]),
        "boolean"=> false,
        "missing" => missing,
        "empty set" => Set(),
        "set" => Set([1, 2, 3]),
        "set{any}" => Set(Any[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]),
        "type" => Any,
        "nested" => Example(
            Dict(
                "a"=>Example(
                    [1, 2, 3],
                    2.0,
                    ABC(1, 2.0im, 3.12f0),
                ),
            ),
            undef,
            ABC(nothing, 1.2+2.1im, π),
        )
    ),
    undef,
    ABC(nothing, 1.2+2.1im, π),
)

The previous efforts both use some smarter way of handling formats, where GarishPrint’s implementation is kinda “dumb”: it only revise Julia’s own Base.show infrastructure with structural printing and colors and depends on some Julia internal printing infrastructure (well that’s the price I have to pay), but it makes things work more consistent with Julia itself.

What’s more?! I’m planning to move the HTML printing from Configurations to this package, and GarishPrint.pprint already supports custom mime type and integrate it with Pluto of course! Stay tuned!

30 Likes

Oh and I wanted to integrate this package with Preference so that you can tune your own favorite color, but I need to wait for the next Julia patch due to this: fix preference loading for non string value by Roger-luo · Pull Request #41294 · JuliaLang/julia · GitHub so for those who deosn’t like my default color schema, wait for the next julia release!

5 Likes