Module: Foreman::Engine::CLI::Color

Defined in:
lib/foreman/engine/cli.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, force = false) ⇒ Object



27
28
29
30
# File 'lib/foreman/engine/cli.rb', line 27

def self.enable(io, force=false)
  io.extend(self)
  @@color_force = force
end

Instance Method Details

#color(name) ⇒ Object



39
40
41
42
43
# File 'lib/foreman/engine/cli.rb', line 39

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

#color?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/foreman/engine/cli.rb', line 32

def color?
  return true if @@color_force
  return false if Foreman.windows?
  return false unless self.respond_to?(:isatty)
  self.isatty && ENV["TERM"]
end