Module: RubyInstaller::Build::Colors

Included in:
RubyInstaller::Build::Components::Base
Defined in:
lib/ruby_installer/build/colors.rb

Constant Summary collapse

ESC =

Start an escape sequence

"\e["
NND =

End the escape sequence

"#{ESC}0m"
ColorMap =
{
  black: 0,
  red: 1,
  green: 2,
  yellow: 3,
  blue: 4,
  magenta: 5,
  cyan: 6,
  white: 7,
}

Class Method Summary collapse

Class Method Details

.colored(color, string) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ruby_installer/build/colors.rb', line 34

def colored(color, string)
  @colors_on = $stdout.tty? if @colors_on.nil?
  if @colors_on
    c = ColorMap[color] || color
    "#{ESC}#{30+c}m#{string}#{NND}"
  else
    string.dup
  end
end

.disable_colorsObject



48
49
50
# File 'lib/ruby_installer/build/colors.rb', line 48

def disable_colors
  @colors_on = false
end

.enable_colorsObject



44
45
46
# File 'lib/ruby_installer/build/colors.rb', line 44

def enable_colors
  @colors_on = true
end

.initialize(*_, **_) ⇒ Object



29
30
31
32
# File 'lib/ruby_installer/build/colors.rb', line 29

def initialize(*_, **_)
  super
  @colors_on = nil
end