Module: Treebis::Colorize
- Included in:
- FileUtilsProxy, Stylize, Task::RunContext
- Defined in:
- lib/treebis.rb
Constant Summary collapse
- Codes =
{:bright=>'1', :red=>'31', :green=>'32', :yellow=>'33', :blue=>'34',:magenta=>'35',:bold=>'1',:blink=>'5'}
Class Method Summary collapse
Class Method Details
.colorize(str, *codenames) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/treebis.rb', line 97 def colorize str, *codenames return str if codenames == [nil] || codenames.empty? codes = nil if codenames.first == :background fail("not yet") unless codenames.size == 2 codes = ["4#{Codes[codenames.last][1..1]}"] # this isn't really excusable in any way else codes = codenames.map{|x| Codes[x]} end "\e["+codes.join(';')+"m#{str}\e[0m" end |