Method: Hammock::StringPatches::InstanceMethods::Colorizer.colorize
- Defined in:
- lib/hammock/monkey_patches/string.rb
.colorize(text, description) ⇒ Object
193 194 195 196 197 198 199 200 |
# File 'lib/hammock/monkey_patches/string.rb', line 193 def colorize text, description terms = " #{description} ".gsub(' light ', ' light_').gsub(' on ', ' on_').strip.split(/\s+/) bg = terms.detect {|i| /on_#{ColorRegex}/ =~ i } fg = terms.detect {|i| ColorRegex =~ i } ctrl = terms.detect {|i| CtrlRegex =~ i } "\e[#{"0;#{fg_for(fg)};#{bg_for(bg) || ctrl_for(ctrl)}"}m#{text}\e[0m" end |