Class: ConsoleFormatter
- Inherits:
-
Object
- Object
- ConsoleFormatter
- Defined in:
- lib/hiptest-publisher/formatters/console_formatter.rb
Instance Attribute Summary collapse
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #dump_error(error, message = nil) ⇒ Object
-
#initialize(verbose) ⇒ ConsoleFormatter
constructor
A new instance of ConsoleFormatter.
- #show_options(options, message = nil) ⇒ Object
- #show_status_message(message, status = nil) ⇒ Object
- #show_verbose_message(message) ⇒ Object
Constructor Details
#initialize(verbose) ⇒ ConsoleFormatter
Returns a new instance of ConsoleFormatter.
6 7 8 9 10 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 6 def initialize(verbose) @verbose = verbose @immediate_verbose = true @verbose_messages = [] end |
Instance Attribute Details
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 4 def verbose @verbose end |
Instance Method Details
#dump_error(error, message = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 12 def dump_error(error, = nil) return unless verbose puts .blue if line = "-" * 80 puts line.yellow puts "#{error.class.name}: #{error.}".red puts "#{error.backtrace.map {|l| " #{l}\n"}.join}".yellow puts line.yellow end |
#show_options(options, message = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 22 def (, = nil) return unless verbose ||= "Running Hiptest-publisher #{hiptest_publisher_version} with:" puts .yellow .each { |k, v| puts " - #{k}: #{v.inspect}" } end |
#show_status_message(message, status = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 38 def (, status=nil) status_icon = " " output = STDOUT if status == :success status_icon = "v".green elsif status == :warning status_icon = "?".yellow elsif status == :failure status_icon = "x".red output = STDERR end if status @immediate_verbose = true cursor_offset = "" else return unless $stdout.tty? rows, columns = IO.console.winsize return if columns == 0 @immediate_verbose = false vertical_offset = (4 + .length) / columns cursor_offset = "\r\e[#{vertical_offset + 1}A" end output.print "[#{status_icon}] #{}#{cursor_offset}\n" if @immediate_verbose && !@verbose_messages.empty? @verbose_messages.each { || () } @verbose_messages.clear end end |
#show_verbose_message(message) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 29 def () return unless verbose if @immediate_verbose STDOUT.print "#{}\n" else @verbose_messages << end end |