https://github.com/tpapp/indentwrappers.jl
Wrapper type for indentation management for plain text printing.
https://github.com/tpapp/indentwrappers.jl
Last synced: over 1 year ago
JSON representation
Wrapper type for indentation management for plain text printing.
- Host: GitHub
- URL: https://github.com/tpapp/indentwrappers.jl
- Owner: tpapp
- License: other
- Created: 2019-01-31T12:24:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-15T14:35:58.000Z (about 5 years ago)
- Last Synced: 2025-02-28T16:20:11.541Z (over 1 year ago)
- Language: Julia
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# IndentWrappers

[](https://travis-ci.com/tpapp/IndentWrappers.jl)
[](http://codecov.io/github/tpapp/IndentWrappers.jl?branch=master)
## Usage
`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:
```julia
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
julia> Foo(['a', 42, "string"])
This is a Foo with the following contents:
a
42
string
```
## Similar packages
- [IOIndents.jl](https://github.com/KristofferC/IOIndents.jl), which inspired part of the implementation