Class: FPM::Cookery::Log::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/cookery/log/color.rb

Constant Summary collapse

CODES =
{
  :black   => 30,
  :blue    => 34,
  :cyan    => 36,
  :green   => 32,
  :magenta => 35,
  :red     => 31,
  :reset   => 0,
  :white   => 39,
  :yellow  => 33,
}

Class Method Summary collapse

Class Method Details

.black(string, type = nil) ⇒ Object



35
# File 'lib/fpm/cookery/log/color.rb', line 35

def black(string, type = nil)   colorize(string, :black, type)   end

.blue(string, type = nil) ⇒ Object



36
# File 'lib/fpm/cookery/log/color.rb', line 36

def blue(string, type = nil)    colorize(string, :blue, type)    end

.color(name, type = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fpm/cookery/log/color.rb', line 18

def color(name, type = nil)
  tint = CODES[name] || 0

  case type
  when :bold
    escape("1;#{tint}")
  when :underline
    escape("4;#{tint}")
  else
    escape(tint)
  end
end

.colorize(string, tint, type = nil) ⇒ Object



31
32
33
# File 'lib/fpm/cookery/log/color.rb', line 31

def colorize(string, tint, type = nil)
  "#{color(tint, type)}#{string}#{color(:reset)}"
end

.cyan(string, type = nil) ⇒ Object



37
# File 'lib/fpm/cookery/log/color.rb', line 37

def cyan(string, type = nil)    colorize(string, :cyan, type)    end

.green(string, type = nil) ⇒ Object



38
# File 'lib/fpm/cookery/log/color.rb', line 38

def green(string, type = nil)   colorize(string, :green, type)   end

.magenta(string, type = nil) ⇒ Object



39
# File 'lib/fpm/cookery/log/color.rb', line 39

def magenta(string, type = nil) colorize(string, :magenta, type) end

.red(string, type = nil) ⇒ Object



40
# File 'lib/fpm/cookery/log/color.rb', line 40

def red(string, type = nil)     colorize(string, :red, type)     end

.reset(string, type = nil) ⇒ Object



41
# File 'lib/fpm/cookery/log/color.rb', line 41

def reset(string, type = nil)   colorize(string, :reset, type)   end

.white(string, type = nil) ⇒ Object



42
# File 'lib/fpm/cookery/log/color.rb', line 42

def white(string, type = nil)   colorize(string, :white, type)   end

.yellow(string, type = nil) ⇒ Object



43
# File 'lib/fpm/cookery/log/color.rb', line 43

def yellow(string, type = nil)  colorize(string, :yellow, type)  end