def color(*options)
return '' if mode.zero? || options.empty?
mix = []
color_seen = false
colors = ANSI_COLORS_FOREGROUND
options.each{ |option|
case option
when Symbol
if color = colors[option]
mix << color
color_seen = :set
elsif ANSI_EFFECTS.key?(option)
mix << effect(option)
elsif option == :random
mix << random(color_seen)
color_seen = :set
else
raise ArgumentError, "Unknown color or effect: #{ option }"
end
when Array
if option.size == 3 && option.all?{ |n| n.is_a? Numeric }
mix << rgb(*(option + [color_seen]))
color_seen = :set
else
raise ArgumentError, "Array argument must contain 3 numerals"
end
when ::String
if option =~ /^#?(?:[0-9a-f]{3}){1,2}$/i
mix << hex(option, color_seen)
color_seen = :set
else
mix << rgb_name(option, color_seen)
color_seen = :set
end
when Numeric
integer = option.to_i
color_seen = :set if (30..49).include?(integer)
mix << integer
when nil
color_seen = :set
else
raise ArgumentError, "Invalid argument: #{ option.inspect }"
end
if color_seen == :set
colors = ANSI_COLORS_BACKGROUND
color_seen = true
end
}
wrap(*mix)
end