All Projects → rbt-lang → Prettyprinting.jl

rbt-lang / Prettyprinting.jl

Licence: mit
Julia library for optimal formatting of composite data structures on a fixed-width terminal.

Programming Languages

julia
2034 projects

PrettyPrinting.jl

PrettyPrinting is a Julia library for optimal formatting of composite data structures on a fixed-width terminal.

Build Status Code Coverage Status Open Issues Documentation MIT License

Quick Start

Install the package using the Julia package manager:

julia> using Pkg
julia> Pkg.add("PrettyPrinting")

To start using the package, import it:

julia> using PrettyPrinting

Use function pprint() to display complex data structures. 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 = 101442, rate = missing), (name = "NANCY A", position = "POLICE OFFICER", salary = 80016, rate = missing)])
 (name = "OEMC", employees = NamedTuple{(:name, :position, :salary, :rate),Tuple{String,String,Missing,Float64}}[(name = "LAKENYA A", position = "CROSSING GUARD", salary = missing, rate = 17.68), (name = "DORIS A", position = "CROSSING GUARD", salary = missing, rate = 19.38)])

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)])]

PrettyPrinting knows how to format tuples, vectors, and dictionaries. Other data types should implement the function tile() as described in the Documentation.

Acknowledgements

The algorithm for finding the optimal layout is based upon Phillip Yelland, A New Approach to Optimal Code Formatting, 2016.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].