module Colored
Constants
- COLORS
- EXTRAS
Public Instance Methods
color(color_name)
click to toggle source
# File lib/colored.rb, line 71 def color(color_name) return '' if String.colors_disabled background = color_name.to_s =~ /on_/ color_name = color_name.to_s.sub('on_', '') return unless color_name && COLORS[color_name] "\e[#{COLORS[color_name] + (background ? 10 : 0)}m" end
colorize(string, options = {})
click to toggle source
# File lib/colored.rb, line 55 def colorize(string, options = {}) colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * '' colored << string colored << extra(:clear) end
colors()
click to toggle source
# File lib/colored.rb, line 61 def colors @@colors ||= COLORS.keys.sort end
extra(extra_name)
click to toggle source
# File lib/colored.rb, line 65 def extra(extra_name) return '' if String.colors_disabled extra_name = extra_name.to_s "\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name] end