class Loupe::Color

Color

This class is responsible for coloring strings.

Constants

COLORS

@return [Hash<Symbol, String>]

Public Class Methods

new(enabled) click to toggle source

@param enabled [Boolean]

# File lib/loupe/color.rb, line 17
def initialize(enabled)
  @enabled = enabled
end

Public Instance Methods

p(string, color) click to toggle source

@param string [String, Symbol] @param color [Symbol] @return [String]

# File lib/loupe/color.rb, line 24
def p(string, color)
  return string unless @enabled

  color_code = COLORS[color]
  "\033[1;#{color_code}m#{string}\033[0m"
end