io_indent

Version, currently main branch1 version
  • main branchlatestOct 22, 2024

github.com/plambert/io_indent.cr

Crystal library to wrap an IO with nested indentation

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  io_indent:
    github: plambert/io_indent.cr
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.14.0
License
MIT
Author
Paul M. Lambert

Dependencies

This version declares no dependencies.

README

IO::Indent

Wrap an IO with automatic indentation. When a character is written at the start of a line, indentation will be added. But only when a character is written, not after every EOL character.

Installation

Add it to your shard.yml:

dependencies:
  io_indent:
    github: plambert/io_indent.cr

Usage

Wrap an IO with a new IO::Indent, then write to it as normal. Any attempt to read will raise an exception.

io = IO::Indent.new(STDOUT)
io.puts "this is not indented"
io.indent do
  io.puts "this is indented by two spaces"
  io.indent
  io.puts "one more level of indentation"
  io.outdent
end
io.puts "back to the left"

This will produce:

this is not indented
  this is indented by two spaces
    one more level of indentation
back to the left

Contributing

  1. Fork it (https://github.com/plambert/io_indent.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors