Class: Reviewer::Output
- Inherits:
-
Object
- Object
- Reviewer::Output
- Defined in:
- lib/reviewer/output.rb,
lib/reviewer/output/token.rb,
lib/reviewer/output/printer.rb,
lib/reviewer/output/scrubber.rb
Overview
Friendly API for printing nicely-formatted output to the console
Defined Under Namespace
Classes: Printer, Scrubber, Token
Constant Summary collapse
- DEFAULT_CONSOLE_WIDTH =
120
- DIVIDER =
'ยท'
Instance Attribute Summary collapse
-
#printer ⇒ Object
readonly
Returns the value of attribute printer.
Instance Method Summary collapse
-
#batch_summary(tool_count, seconds) ⇒ void
Prints a summary of the total time and results for a batch run.
- #clear ⇒ Object
-
#current_command(command) ⇒ void
Prints the text of a command to the console to help proactively expose potentials issues with syntax if Reviewer translated thte provided options in an unexpected way.
- #divider ⇒ Object
- #failure(details, command: nil) ⇒ Object
- #guidance(summary, details) ⇒ Object
-
#help(message) ⇒ void
Prints plain text to the console.
-
#initialize(printer = Printer.new) ⇒ Output
constructor
Creates an instance of Output to print Reviewer activity and results to the console.
- #newline ⇒ Object
- #success(timer) ⇒ Object
-
#tool_summary(tool) ⇒ void
Print a tool summary using the name and description.
- #unfiltered(value) ⇒ Object
- #unrecoverable(details) ⇒ Object
Constructor Details
Instance Attribute Details
#printer ⇒ Object (readonly)
Returns the value of attribute printer.
15 16 17 |
# File 'lib/reviewer/output.rb', line 15 def printer @printer end |
Instance Method Details
#batch_summary(tool_count, seconds) ⇒ void
This method returns an undefined value.
Prints a summary of the total time and results for a batch run. If multiple tools, it will
show the total tool count
49 50 51 52 |
# File 'lib/reviewer/output.rb', line 49 def batch_summary(tool_count, seconds) printer.print(:bold, "~#{seconds.round(1)} seconds") printer.puts(:muted, " for #{tool_count} tools") if tool_count > 1 end |
#clear ⇒ Object
22 23 24 |
# File 'lib/reviewer/output.rb', line 22 def clear system('clear') end |
#current_command(command) ⇒ void
This method returns an undefined value.
Prints the text of a command to the console to help proactively expose potentials issues with
syntax if Reviewer translated thte provided options in an unexpected way
69 70 71 72 |
# File 'lib/reviewer/output.rb', line 69 def current_command(command) printer.puts(:bold, 'Now Running:') printer.puts(:default, String(command)) end |
#divider ⇒ Object
30 31 32 33 |
# File 'lib/reviewer/output.rb', line 30 def divider newline printer.print(:muted, DIVIDER * console_width) end |
#failure(details, command: nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/reviewer/output.rb', line 82 def failure(details, command: nil) printer.print(:failure, 'Failure') printer.puts(:muted, " #{details}") return if command.nil? newline printer.puts(:bold, 'Failed Command:') printer.puts(:muted, String(command)) end |
#guidance(summary, details) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/reviewer/output.rb', line 98 def guidance(summary, details) return if details.nil? newline printer.puts(:bold, summary) printer.puts(:muted, details) end |
#help(message) ⇒ void
This method returns an undefined value.
Prints plain text to the console
39 40 41 |
# File 'lib/reviewer/output.rb', line 39 def help() printer.puts(:default, ) end |
#newline ⇒ Object
26 27 28 |
# File 'lib/reviewer/output.rb', line 26 def newline printer.puts(:default, '') end |
#success(timer) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/reviewer/output.rb', line 74 def success(timer) printer.print(:success, 'Success') printer.print(:success_light, " #{timer.total_seconds}s") printer.print(:warning_light, " (#{timer.prep_percent}% prep ~#{timer.prep_seconds}s)") if timer.prepped? newline newline end |
#tool_summary(tool) ⇒ void
This method returns an undefined value.
Print a tool summary using the name and description. Used before running a command to help
identify which tool is running at any given moment.
59 60 61 62 |
# File 'lib/reviewer/output.rb', line 59 def tool_summary(tool) printer.print(:bold, tool.name) printer.puts(:muted, " #{tool.description}") end |
#unfiltered(value) ⇒ Object
106 107 108 109 110 |
# File 'lib/reviewer/output.rb', line 106 def unfiltered(value) return if value.nil? || value.strip.empty? printer.stream << value end |
#unrecoverable(details) ⇒ Object
93 94 95 96 |
# File 'lib/reviewer/output.rb', line 93 def unrecoverable(details) printer.puts(:error, 'Unrecoverable Error:') printer.puts(:muted, details) end |