Module: Wright::Util::Color

Defined in:
lib/wright/util/color.rb

Overview

Internal: ANSI color helpers.

Class Method Summary collapse

Class Method Details

.colorize(string, color) ⇒ Object

Internal: Colorize a string.

string - The string to colorize. color - The color that should be used.

Examples

Wright::Util::Color.colorize('Hello world', :red)
# => "\e[31mHello world\e[0m"

Wright::Util::Color.colorize('Hello world', :yellow)
# => "\e[32mHello world\e[0m"

Returns the colorized String.



37
38
39
40
41
# File 'lib/wright/util/color.rb', line 37

def self.colorize(string, color)
  no_color = COLOR_MAP[:none]
  color = COLOR_MAP.fetch(color, no_color)
  "#{color}#{string}#{no_color}"
end

.red(string) ⇒ Object

Internal: Colorize a string (red).

string - The string to colorize.

Returns the colorized String.



10
11
12
# File 'lib/wright/util/color.rb', line 10

def self.red(string)
  colorize(string, :red)
end

.yellow(string) ⇒ Object

Internal: Colorize a string (yellow).

string - The string to colorize.

Returns the colorized String.



19
20
21
# File 'lib/wright/util/color.rb', line 19

def self.yellow(string)
  colorize(string, :yellow)
end