Permalink
Browse files

Much nicer fancy printer implementation

  • Loading branch information...
1 parent 073616e commit adeaaa71659f97a4b38db76a46b6395303820699 @quackingduck quackingduck committed Apr 28, 2010
Showing with 29 additions and 20 deletions.
  1. +29 −20 lib/result_printer.rb
View
@@ -25,42 +25,51 @@ def yaml
end
def fancy
- # •∙ are inverted in my terminal font (Incosolata) so I'm swapping them
require 'term/ansicolor'
case status
- when :info : blue format_info("#{name}", result)
- when :infos
- formatted_result = result.map do |r|
- # TODO: successful ones should be green
- format_info("#{{'success' => '', 'info' => '' }[r['status']]} #{r['name']}", r['result']).rstrip
- end.join("\n")
- blue("#{name}\n#{formatted_result.indent}")
- when :success
- green("#{name}")
- when :failure
- # sooo hacky
- failure = result.find { |r| r['status'] == 'failure' }
- out = failure.dup
- out.delete('status')
- out.delete('name')
- color(:red, "#{name} - #{failure['name']}\n#{YAML.without_header(out).indent}")
+ when :info : blue format_info(name, result)
+ when :success : green icon(status) + ' ' + name
+ when :infos : blue icon(status) + ' ' + name + "\n" + fancy_result(result).indent
+ when :failure : red icon(status) + ' ' + name + "\n" + fancy_result(result).indent
when :error
class_and_message = "#{result['class']} - #{result['message']}"
backtrace = result['backtrace'].join("\n")
- color(:red, "#{name}\n#{class_and_message.indent}\n#{backtrace.indent}")
+ red icon(status) + ' ' + name + "\n" + class_and_message.indent + "\n" + backtrace.indent
end
end
- def blue(str) color(:blue,str) end
+ def fancy_result(checks)
+ result.map do |r|
+ status, name, result = r['status'].to_sym, r['name'], r['result']
+ case status
+ when :success : green icon(status) + ' ' + name
+ when :failure : red icon(status) + ' ' + name
+ when :info : blue format_info(name, result)
+ end
+ end.join("\n")
+ end
+
+ def icon(status)
+ case status.to_sym
+ when :info : ''
+ when :infos : ''
+ when :failure : ''
+ when :success : ''
+ when :error : '' # skull and crossbone, aww yeah
+ end
+ end
+
+ def blue(str) color(:blue,str) end
def green(str) color(:green,str) end
+ def red(str) color(:red,str) end
def color(color, str)
[Term::ANSIColor.send(color), str, Term::ANSIColor.reset].join
end
# whatahack
def format_info(str, result)
- YAML.without_header({'FANCY' => result}).sub('FANCY', str)
+ YAML.without_header({'FANCY' => result}).sub('FANCY', icon(:info) + ' ' + str).rstrip
end
end

0 comments on commit adeaaa7

Please sign in to comment.