Module: Foreman::Color

Defined in:
lib/foreman/color.rb

Constant Summary collapse

ANSI =
{
  :reset          => 0,
  :black          => 30,
  :red            => 31,
  :green          => 32,
  :yellow         => 33,
  :blue           => 34,
  :magenta        => 35,
  :cyan           => 36,
  :white          => 37,
  :bright_black   => 30,
  :bright_red     => 31,
  :bright_green   => 32,
  :bright_yellow  => 33,
  :bright_blue    => 34,
  :bright_magenta => 35,
  :bright_cyan    => 36,
  :bright_white   => 37,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enable(io) ⇒ Object



25
26
27
# File 'lib/foreman/color.rb', line 25

def self.enable(io)
  io.extend(self)
end

Instance Method Details

#color(name) ⇒ Object



34
35
36
37
38
# File 'lib/foreman/color.rb', line 34

def color(name)
  return "" unless color?
  return "" unless ansi = ANSI[name.to_sym]
  "\e[#{ansi}m"
end

#color?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/foreman/color.rb', line 29

def color?
  return false unless self.respond_to?(:isatty)
  self.isatty && ENV["TERM"]
end