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
- #ask(question) ⇒ Object
- #colored? ⇒ Boolean
- #dump_error(error, message = nil) ⇒ Object
-
#initialize(verbose, color: nil) ⇒ ConsoleFormatter
constructor
A new instance of ConsoleFormatter.
- #show_error(message) ⇒ Object
- #show_failure(message) ⇒ Object
- #show_options(options, message = nil) ⇒ Object
- #show_status_message(message, status = nil) ⇒ Object
- #show_verbose_message(message) ⇒ Object
Constructor Details
#initialize(verbose, color: nil) ⇒ ConsoleFormatter
Returns a new instance of ConsoleFormatter.
8 9 10 11 12 13 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 8 def initialize(verbose, color: nil) @verbose = verbose @color = color.nil? ? tty? : color @immediate_verbose = true @verbose_messages = [] end |
Instance Attribute Details
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 6 def verbose @verbose end |
Instance Method Details
#ask(question) ⇒ Object
82 83 84 85 86 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 82 def ask(question) return unless tty? STDOUT.print "[#{colorize('?', :yellow)}] #{question}" return $stdin.gets.chomp.downcase.strip end |
#colored? ⇒ Boolean
88 89 90 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 88 def colored? @color end |
#dump_error(error, message = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 15 def dump_error(error, = nil) return unless verbose puts colorize(, :blue) if line = "-" * 80 puts colorize(line, :yellow) puts colorize("#{error.class.name}: #{error.}", :red) puts colorize("#{error.backtrace.map {|l| " #{l}\n"}.join}", :yellow) puts colorize(line, :yellow) end |
#show_error(message) ⇒ Object
25 26 27 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 25 def show_error() STDOUT.print colorize(, :yellow) end |
#show_failure(message) ⇒ Object
29 30 31 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 29 def show_failure() STDOUT.print(colorize(, :red)) end |
#show_options(options, message = nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 33 def (, = nil) return unless verbose ||= I18n.t(:verbose_header, version: hiptest_publisher_version) puts colorize(, :yellow) .each { |k, v| puts " - #{k}: #{v.inspect}" } end |
#show_status_message(message, status = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 49 def (, status=nil) status_icon = " " output = STDOUT if status == :success status_icon = colorize("v", :green) elsif status == :warning status_icon = colorize("?", :yellow) elsif status == :failure status_icon = colorize("x", :red) output = STDERR end if status @immediate_verbose = true cursor_offset = "" else return unless tty? return if IO.console.nil? 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
40 41 42 43 44 45 46 47 |
# File 'lib/hiptest-publisher/formatters/console_formatter.rb', line 40 def () return unless verbose if @immediate_verbose STDOUT.print "#{}\n" else @verbose_messages << end end |