Module: Bmo2::Color

Extended by:
Color
Included in:
Color, Command
Defined in:
lib/bmo2/color.rb

Constant Summary collapse

CODES =
{
  :reset   => "\e[0m",
  :cyan    => "\e[36m",
  :magenta => "\e[35m",
  :red     => "\e[31m",
  :green   => "\e[32m",
  :yellow  => "\e[33m"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



14
15
16
17
18
19
# File 'lib/bmo2/color.rb', line 14

def self.included(other)
  if RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/
    require 'Win32/Console/ANSI'
  end
rescue LoadError
end

Instance Method Details

#colorize(string, color_code) ⇒ Object



21
22
23
24
25
26
# File 'lib/bmo2/color.rb', line 21

def colorize(string, color_code)
  if !defined?(Win32::Console) && !!(RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/)
    return string
  end
  "#{CODES[color_code] || color_code}#{string}#{CODES[:reset]}"
end