diff options
-rwxr-xr-x | lib/highline.rb | 18 | ||||
-rwxr-xr-x | test/test_highline.rb | 5 |
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index ac38035..481e5bd 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -305,24 +305,24 @@ class HighLine # ends with a space or tab character, a newline will not be appended (output # will be flush()ed). All other cases are passed straight to Kernel.puts(). # - # The _statement_ parameter is processed as an ERb template, supporting - # embedded Ruby code. The template is evaluated with a binding inside - # the HighLine instance, providing easy access to the ANSI color constants - # and the HighLine.color() method. + # The _statement_ argument is processed as an ERb template, supporting + # embedded Ruby code. The template is evaluated within a HighLine + # instance's binding for providing easy access to the ANSI color constants + # and the HighLine#color() method. # - def say( statement ) + def say(statement) statement = render_statement(statement) return if statement.empty? - out = (indentation+statement) + statement = (indentation+statement) # Don't add a newline if statement ends with whitespace, OR # if statement ends with whitespace before a color escape code. if /[ \t](\e\[\d+(;\d+)*m)?\Z/ =~ statement - @output.print(out) - @output.flush + output.print(statement) + output.flush else - @output.puts(out) + output.puts(statement) end end diff --git a/test/test_highline.rb b/test/test_highline.rb index 0eb803e..4060c93 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -1221,6 +1221,11 @@ class TestHighLine < Minitest::Test assert_equal("This will not have a newline. ", @output.string) @output.truncate(@output.rewind) + + @terminal.say("This will not have a newline.\t") + assert_equal("This will not have a newline.\t", @output.string) + + @output.truncate(@output.rewind) @terminal.say("This will not\n end with a newline. ") assert_equal("This will not\n end with a newline. ", @output.string) |