Module: Goethe::Tech
- Defined in:
- lib/goethe.rb
Constant Summary collapse
- Colors =
[:black, :red, :green, :yellow, :blue, :purple, :cyan, :white]
- BG =
ANSI codes
- FG =
- Mod =
{ :bold => '1', :bright => '1', :underline => '4', :blink => '5'}
- ESC =
"\033["- UNESC =
'm'- RESET =
ESC + '0' + UNESC
Class Method Summary collapse
Class Method Details
.colorize(fg, args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/goethe.rb', line 32 def self.colorize( fg, args ) text = args.select {|arg| arg.is_a? String }.join deco = (args & Mod.keys) pre = deco.empty? ? nil : deco.map {|k| Mod[k] }.join(';') match = (args & Colors).first bg = match ? BG[match] : nil code = [ pre, FG[fg], bg ].compact.join( ';' ) ESC + code + UNESC + text + RESET end |