Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#colorize(code) ⇒ Object

Public: Colorize a string for a Unix terminal.

code - The color code: a Numeric [0-255] or a Symbol [:red, :green, :orange, :purple, :rose].

Returns a colorized string.



16
17
18
19
20
# File 'lib/cli/core_ext.rb', line 16

def colorize code
  colors = { red: 31, green: 32, orange: 33, purple: 34, rose: 35 }
  code = colors[code]  unless code.kind_of? Numeric
  "\e[#{code}m#{self}\e[0m"
end