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.

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"

Parameters:

  • string (String)

    the string to colorize

  • color (String)

    the color that should be used

Returns:

  • (String)

    the colorized string


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).

Parameters:

  • string (String)

    the string to colorize

Returns:

  • (String)

    the colorized string


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).

Parameters:

  • string (String)

    the string to colorize

Returns:

  • (String)

    the colorized string


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

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