Module: Wright::Util::Color Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

ANSI color helpers.

Constant Summary collapse

COLOR_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  none: "\e[0m",
  red: "\e[31m",
  yellow: "\e[33m"
}

Class Method Summary collapse

Class Method Details

.colorize(string, color) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Colorizes a string.

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"

36
37
38
39
40
# 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) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Colorizes a string (red).


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

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

.yellow(string) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Colorizes a string (yellow).


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

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