lib/tty/shell/statement.rb in tty-0.0.11 vs lib/tty/shell/statement.rb in tty-0.1.0
- old
+ new
@@ -1,19 +1,24 @@
-# -*- encoding: utf-8 -*-
+# encoding: utf-8
module TTY
+ # A class responsible for shell prompt interactions.
class Shell
-
# A class representing a statement output to shell.
class Statement
-
# @api private
attr_reader :shell
private :shell
+ # Flag to display newline
+ #
+ # @api public
attr_reader :newline
+ # Color used to display statement
+ #
+ # @api public
attr_reader :color
# Initialize a Statement
#
# @param [TTY::Shell] shell
@@ -25,31 +30,30 @@
#
# @option options [Symbol] :color
# change the message display to color
#
# @api public
- def initialize(shell=nil, options={})
- @shell = shell || Shell.new
- @newline = options.fetch :newline, true
- @color = options.fetch :color, nil
+ def initialize(shell = Shell.new, options = {})
+ @shell = shell
+ @newline = options.fetch(:newline, true)
+ @color = options.fetch(:color, nil)
end
# Output the message to the shell
#
# @param [String] message
# the message to be printed to stdout
#
# @api public
def declare(message)
- message = TTY::terminal.color.set message, *color if color
+ message = TTY.terminal.color.set message, *color if color
if newline && /( |\t)(\e\[\d+(;\d+)*m)?\Z/ !~ message
shell.output.puts message
else
shell.output.print message
shell.output.flush
end
end
-
end # Statement
end # Shell
end # TTY