module Wright::Util::Color

ANSI color helpers.

Constants

COLOR_MAP

Public Class Methods

colorize(string, color) click to toggle source

Colorizes a string.

@param string [String] the string to colorize @param color [String] the color that should be used

@example

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

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

@return [String] the colorized string

# File lib/wright/util/color.rb, line 36
def self.colorize(string, color)
  no_color = COLOR_MAP[:none]
  color = COLOR_MAP.fetch(color, no_color)
  "#{color}#{string}#{no_color}"
end
red(string) click to toggle source

Colorizes a string (red).

@param string [String] the string to colorize

@return [String] the colorized string

# File lib/wright/util/color.rb, line 10
def self.red(string)
  colorize(string, :red)
end
yellow(string) click to toggle source

Colorizes a string (yellow).

@param string [String] the string to colorize

@return [String] the colorized string

# File lib/wright/util/color.rb, line 19
def self.yellow(string)
  colorize(string, :yellow)
end