Module: RedGreen::Color

Defined in:
lib/redgreen.rb

Constant Summary collapse

COLORS =

# 37 = white, 30 = black

FG_COLORS = { :for_clear => 37, :for_red => 37, :for_green => 37, :for_yellow => 30}
BG_COLORS = { :clear => 0, :red => 41, :green => 42, :yellow => 43 }
def self.method_missing(color_name, *args)
  color(color_name) + args.first + color(:clear)
end
def self.color(color)
  fg_color = FG_COLORS["for_#{color}".to_sym]
  bg_color = BG_COLORS[color.to_sym]
  "\e[#{fg_color};#{bg_color}m"
end
{ :clear => 0, :red => 31, :green => 32, :yellow => 33 }

Class Method Summary collapse

Class Method Details

.color(color) ⇒ Object



23
24
25
# File 'lib/redgreen.rb', line 23

def self.color(color)
  "\e[#{COLORS[color.to_sym]}m"
end

.method_missing(color_name, *args) ⇒ Object



20
21
22
# File 'lib/redgreen.rb', line 20

def self.method_missing(color_name, *args)
  color(color_name) + args.first + color(:clear)
end