Fix indent and add empty line method

This commit is contained in:
Michael Miller 2019-03-03 09:54:09 -07:00
parent f73a51ae0c
commit 8cdc5f0b3f
1 changed files with 10 additions and 5 deletions

View File

@ -20,7 +20,7 @@ module Spectator::Formatting
# The *io* is the stream to output to.
# The *indent_size* is how much (number of spaces) to indent at each level.
# The *initial_indent* is what the ident should be set to.
def initialize(@io : IO, @indent_size = INDENT_SIZE, @inital_indent = 0)
def initialize(@io : IO, @indent_size = INDENT_SIZE, inital_indent @indent = 0)
end
# Indents the text and yields.
@ -30,15 +30,20 @@ module Spectator::Formatting
# Indents the text by a specified amount and yields.
def increase(amount) : Nil
@indent_size += amount
@indent += amount
yield
ensure
@indent_size -= amount
@indent -= amount
end
# Produces an empty line.
def line
@io.puts
end
# Produces a line of indented text.
def line(text)
@indent_size.times { io << ' ' }
@indent.times { @io << ' ' }
@io.puts text
end
end