Class: Printer
- Inherits:
-
Object
- Object
- Printer
- Defined in:
- lib/printer.rb
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #color(string, *colors) ⇒ Object
-
#color? ⇒ Boolean
Should colored output be used? Only on TTY.
-
#error(message) ⇒ Object
Print an error message.
-
#fatal(message) ⇒ Object
Print a message describing a fatal error.
- #highline ⇒ Object
-
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Printer
constructor
A new instance of Printer.
-
#msg(message) ⇒ Object
(also: #info)
Prints a message to stdout.
-
#warn(message) ⇒ Object
Print a warning message.
Constructor Details
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Printer
Returns a new instance of Printer.
6 7 8 |
# File 'lib/printer.rb', line 6 def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN) @stdout, @stderr, @stdin = stdout, stderr, stdin end |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
3 4 5 |
# File 'lib/printer.rb', line 3 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
4 5 6 |
# File 'lib/printer.rb', line 4 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
2 3 4 |
# File 'lib/printer.rb', line 2 def stdout @stdout end |
Instance Method Details
#color(string, *colors) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/printer.rb', line 41 def color(string, *colors) if color? highline.color(string, *colors) else string end end |
#color? ⇒ Boolean
Should colored output be used? Only on TTY
50 51 52 |
# File 'lib/printer.rb', line 50 def color? true end |
#error(message) ⇒ Object
Print an error message
32 33 34 |
# File 'lib/printer.rb', line 32 def error() msg("#{color('ERROR:', :red, :bold)} #{}") end |
#fatal(message) ⇒ Object
Print a message describing a fatal error.
37 38 39 |
# File 'lib/printer.rb', line 37 def fatal() msg("#{color('FATAL:', :red, :bold)} #{}") end |
#highline ⇒ Object
10 11 12 13 14 15 |
# File 'lib/printer.rb', line 10 def highline @highline ||= begin require 'highline' HighLine.new end end |
#msg(message) ⇒ Object Also known as: info
Prints a message to stdout. Aliased as info for compatibility with the logger API.
19 20 21 22 |
# File 'lib/printer.rb', line 19 def msg() stdout.puts stdout.flush end |
#warn(message) ⇒ Object
Print a warning message
27 28 29 |
# File 'lib/printer.rb', line 27 def warn() msg("#{color('WARNING:', :yellow, :bold)} #{}") end |