indent(io, n)
returns an ::IO
object that writes n
spaces after each \n
.
indent
s 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
- IOIndents.jl, which inspired part of the implementation