[ANN] PrettyPrinting.jl

I’d like to introduce PrettyPrinting.jl, a Julia library for optimal formatting of composite data structures on a fixed-width terminal.

PrettyPrinting exports a function pprint(), which can display any data assembled from tuples, vectors and dictionaries. For example:

julia> data = [(name = "POLICE",
                employees = [(name = "JEFFERY A", position = "SERGEANT", salary = 101442, rate = missing),
                             (name = "NANCY A", position = "POLICE OFFICER", salary = 80016, rate = missing)]),
               (name = "OEMC",
                employees = [(name = "LAKENYA A", position = "CROSSING GUARD", salary = missing, rate = 17.68),
                             (name = "DORIS A", position = "CROSSING GUARD", salary = missing, rate = 19.38)])]
2-element Array{NamedTuple{(:name, :employees),T} where T<:Tuple,1}:
 (name = "POLICE", employees = NamedTuple{(:name, :position, :salary, :rate),Tuple{String,String,Int64,Missing}}[(name = "JEFFERY A", position = "SERGEANT", salary = 10
 (name = "OEMC", employees = NamedTuple{(:name, :position, :salary, :rate),Tuple{String,String,Missing,Float64}}[(name = "LAKENYA A", position = "CROSSING GUARD", salar

julia> using PrettyPrinting

julia> pprint(data)
[(name = "POLICE",
  employees = [(name = "JEFFERY A",
                position = "SERGEANT",
                salary = 101442,
                rate = missing),
               (name = "NANCY A",
                position = "POLICE OFFICER",
                salary = 80016,
                rate = missing)]),
 (name = "OEMC",
  employees = [(name = "LAKENYA A",
                position = "CROSSING GUARD",
                salary = missing,
                rate = 17.68),
               (name = "DORIS A",
                position = "CROSSING GUARD",
                salary = missing,
                rate = 19.38)])]
12 Likes

Nice! Do you think that this could be easily integrated in DocumentFormat.jl to deal with long lines? ( Split lines exceeding width limit · Issue #7 · julia-vscode/DocumentFormat.jl · GitHub )

@Diego_Javier_Zea, indeed, it should be possible to reuse the layout engine to format Julia code.

1 Like