def self.included(base)
HighLine::COLORS.each do |color|
base.class_eval "if public_instance_methods.map { |m| m.to_s }.\ninclude? \"\#{color.downcase}\"\nundef :\#{color.downcase}\nend\ndef \#{color.downcase}\ncolor(:\#{color.downcase})\nend\n"
base.class_eval "if public_instance_methods.map { |m| m.to_s }.\ninclude? \"on_\#{color.downcase}\"\nundef :on_\#{color.downcase}\nend\ndef on_\#{color.downcase}\non(:\#{color.downcase})\nend\n"
HighLine::STYLES.each do |style|
base.class_eval "if public_instance_methods.map { |m| m.to_s }.\ninclude? \"\#{style.downcase}\"\nundef :\#{style.downcase}\nend\ndef \#{style.downcase}\ncolor(:\#{style.downcase})\nend\n"
end
end
base.class_eval do
if public_instance_methods.map { |m| m.to_s }.include? "color"
undef :color
end
if public_instance_methods.map { |m| m.to_s }.include? "foreground"
undef :foreground
end
def color(*args)
self.class.new(HighLine.color(self, *args))
end
alias_method :foreground, :color
if public_instance_methods.map { |m| m.to_s }.include? "on"
undef :on
end
def on(arg)
color(('on_' + arg.to_s).to_sym)
end
if public_instance_methods.map { |m| m.to_s }.include? "uncolor"
undef :uncolor
end
def uncolor
self.class.new(HighLine.uncolor(self))
end
if public_instance_methods.map { |m| m.to_s }.include? "rgb"
undef :rgb
end
def rgb(*colors)
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
color("rgb_#{color_code}".to_sym)
end
if public_instance_methods.map { |m| m.to_s }.include? "on_rgb"
undef :on_rgb
end
def on_rgb(*colors)
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
color("on_rgb_#{color_code}".to_sym)
end
if public_instance_methods.map { |m| m.to_s }.include? "method_missing"
undef :method_missing
end
def method_missing(method, *args, &blk)
if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
color(method)
else
raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>"
end
end
end
end