From 8cdc5f0b3fc3dfc27b7b76bb9c23801cb1f9e1d6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 3 Mar 2019 09:54:09 -0700 Subject: [PATCH] Fix indent and add empty line method --- src/spectator/formatting/indent.cr | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/spectator/formatting/indent.cr b/src/spectator/formatting/indent.cr index a7ec680..103747b 100644 --- a/src/spectator/formatting/indent.cr +++ b/src/spectator/formatting/indent.cr @@ -15,12 +15,12 @@ module Spectator::Formatting private struct Indent # Default number of spaces to indent by. INDENT_SIZE = 2 - + # Creates the identation tracker. # 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