Sha256: eebef2cd7dac3496c9d93ba24b67e7717f31901d18ff20ea720f13ca742d7a0a
Contents?: true
Size: 869 Bytes
Versions: 136
Compression:
Stored size: 869 Bytes
Contents
module Recog class Formatter COLORS = { :red => 31, :yellow => 33, :green => 32, :white => 15 } attr_reader :options, :output def initialize(options, output) @options = options @output = output || StringIO.new end def status_message(text) output.puts color(text, :white) end def success_message(text) output.puts color(text, :green) end def warning_message(text) output.puts color(text, :yellow) end def failure_message(text) output.puts color(text, :red) end private def color_enabled? options.color end def color(text, color_code) color_enabled? ? colorize(text, color_code) : text end def colorize(text, color_code) "\e[#{color_code_for(color_code)}m#{text}\e[0m" end def color_code_for(code) COLORS.fetch(code) { COLORS.fetch(:white) } end end end
Version data entries
136 entries across 136 versions & 2 rubygems