module PhusionPassenger::Utils::AnsiColors

Constants

BLACK_BG
BLUE_BG
BOLD
DEFAULT_TERMINAL_COLOR
DGRAY
GRAY
GREEN
ORANGE
RED
RESET
WHITE
YELLOW

Public Class Methods

included(klass) click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/ansi_colors.rb, line 47
def self.included(klass)
  # When included into another class, make sure that Utils
  # methods are made private.
  public_instance_methods(false).each do |method_name|
    klass.send(:private, method_name)
  end
end
new(type = :auto) click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/ansi_colors.rb, line 43
def self.new(type = :auto)
  AnsiColorsPrinter.new(type)
end

Public Instance Methods

ansi_colorize(text) click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/ansi_colors.rb, line 55
def ansi_colorize(text)
  text = text.gsub(%r{<b>(.*?)</b>}m, "#{BOLD}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<dgray>(.*?)</dgray>}m, "#{BOLD}#{DGRAY}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<gray>(.*?)</gray>}m, "#{BOLD}#{GRAY}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<red>(.*?)</red>}m, "#{BOLD}#{RED}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<orange>(.*?)</orange>}m, "#{BOLD}#{ORANGE}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<green>(.*?)</green>}m, "#{BOLD}#{GREEN}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<yellow>(.*?)</yellow>}m, "#{BOLD}#{YELLOW}\\1#{DEFAULT_TERMINAL_COLOR}")
  text.gsub!(%r{<banner>(.*?)</banner>}m, "#{BOLD}#{BLUE_BG}#{YELLOW}\\1#{DEFAULT_TERMINAL_COLOR}")
  text
end
strip_color_tags(text) click to toggle source
# File src/ruby_supportlib/phusion_passenger/utils/ansi_colors.rb, line 67
def strip_color_tags(text)
  text = text.gsub(%r{<b>(.*?)</b>}m, "\\1")
  text = text.gsub(%r{<dgray>(.*?)</dgray>}m, "\\1")
  text = text.gsub(%r{<gray>(.*?)</gray>}m, "\\1")
  text.gsub!(%r{<red>(.*?)</red>}m, "\\1")
  text.gsub!(%r{<orange>(.*?)</orange>}m, "\\1")
  text.gsub!(%r{<green>(.*?)</green>}m, "\\1")
  text.gsub!(%r{<yellow>(.*?)</yellow>}m, "\\1")
  text.gsub!(%r{<banner>(.*?)</banner>}m, "\\1")
  text
end