IndentWrappers.jl

Wrapper type for indentation management for plain text printing.
Author tpapp
Popularity
1 Star
Updated Last
3 Years Ago
Started In
January 2019

IndentWrappers

Lifecycle Build Status codecov.io

Usage

indent(io, n) returns an ::IO object that writes n spaces after each \n.

indents can be chained, use in a functional way. It is recommended that implementations of Base.show using this package never close with a newline.

Example:

struct Foo
    contents
end

function Base.show(io::IO, foo::Foo)
    print(io, "This is a Foo with the following contents:")
    let inner_io = indent(io, 4)
        for elt in foo.contents
            print(inner_io, '\n', elt)
        end
    end
end

then

julia> Foo(['a', 42, "string"])
This is a Foo with the following contents:
    a
    42
    string

Similar packages