Class: TRMNLP::Reporter
- Inherits:
-
Object
- Object
- TRMNLP::Reporter
- Defined in:
- lib/trmnlp/reporter.rb
Overview
Single sink for user-facing command output. Records every message so specs can assert on what a command would have said, and writes to the underlying stream unless quiet:.
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #green(text) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(quiet: false, stream: $stdout) ⇒ Reporter
constructor
A new instance of Reporter.
- #red(text) ⇒ Object
- #yellow(text) ⇒ Object
Constructor Details
#initialize(quiet: false, stream: $stdout) ⇒ Reporter
Returns a new instance of Reporter.
10 11 12 13 14 15 16 17 |
# File 'lib/trmnlp/reporter.rb', line 10 def initialize(quiet: false, stream: $stdout) @quiet = quiet @stream = stream @messages = [] # Colour only when the stream is a real terminal, so ANSI codes # never leak into piped or redirected output. @tty = stream.tty? end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
8 9 10 |
# File 'lib/trmnlp/reporter.rb', line 8 def @messages end |
Instance Method Details
#green(text) ⇒ Object
24 |
# File 'lib/trmnlp/reporter.rb', line 24 def green(text) = colorize(text, 32) |
#info(message) ⇒ Object
19 20 21 22 |
# File 'lib/trmnlp/reporter.rb', line 19 def info() @messages << @stream.puts() unless @quiet end |
#red(text) ⇒ Object
26 |
# File 'lib/trmnlp/reporter.rb', line 26 def red(text) = colorize(text, 31) |
#yellow(text) ⇒ Object
25 |
# File 'lib/trmnlp/reporter.rb', line 25 def yellow(text) = colorize(text, 33) |