Class: Jefe::ColorPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/jefe.rb

Constant Summary collapse

Color =
Term::ANSIColor
COLORS =
[:cyan, :yellow, :green, :magenta, :red]

Instance Method Summary collapse

Constructor Details

#initializeColorPrinter

Returns a new instance of ColorPrinter.



52
53
54
# File 'lib/jefe.rb', line 52

def initialize
  @colors ||= {"system" => :white}
end

Instance Method Details

#out(name, command) ⇒ Object



55
56
57
58
59
60
# File 'lib/jefe.rb', line 55

def out name, command
  type = name.match(/^([A-Za-z0-9_]+).\d+$/) ? $1 : name
  @colors[type] = COLORS.shift.tap {|c| COLORS.push c} unless @colors[type]
  color = @colors[type]
  puts "#{Color.send color} #{Time.now.strftime '%H:%M:%S'} #{name}#{' ' * (9 - name.length)} | #{Color.reset}#{command.chomp}"
end