Module: ColorMeRad::Colorize
Constant Summary collapse
- CODES =
{ :black => 0, :light_black => 60, :red => 1, :light_red => 61, :green => 2, :light_green => 62, :yellow => 3, :light_yellow => 63, :blue => 4, :light_blue => 64, :magenta => 5, :light_magenta => 65, :cyan => 6, :light_cyan => 66, :white => 7, :light_white => 67, :default => 9 }
Instance Method Summary collapse
Instance Method Details
#colored?(text) ⇒ Boolean
33 34 35 36 |
# File 'lib/color_me_rad/colorize.rb', line 33 def colored?(text) return false unless text.is_a?(String) !!text.match(/\033\[\d{2,3}m/) end |
#colorize(text, foreground, background) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/color_me_rad/colorize.rb', line 17 def colorize(text, foreground, background) return text unless ColorMeRad.enabled? text = set_foreground(text, foreground) if foreground text = set_background(text, background) if background text end |
#show_samples ⇒ Object
26 27 28 29 30 31 |
# File 'lib/color_me_rad/colorize.rb', line 26 def show_samples CODES.keys.permutation(2).each do |background, foreground| = (background, foreground, 13) puts colorize(, foreground, background) end end |