class Cxxproject::ColorizingFormatter

simple class to colorize compiler output the class depends on the rainbow gem

Attributes

enabled[RW]

Public Class Methods

setColorScheme(scheme) click to toggle source

colors are not instance vars due to caching the building blocks

# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 23
def self.setColorScheme(scheme)
  if scheme == :black
    @@warning_color = :yellow
    @@error_color = :red
    @@info_color = :white
    @@additional_info_color = :cyan
    @@success_color = :green
  elsif scheme == :white
    @@warning_color = :magenta
    @@error_color = :red
    @@info_color = :black
    @@additional_info_color = :blue
    @@success_color = :green
  end
end

Public Instance Methods

enabled?() click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 10
def enabled?
  false
end
format(compiler_output, error_descs, error_parser) click to toggle source

formats several lines of usually compiler output

# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 64
def format(compiler_output, error_descs, error_parser)
  return compiler_output if not enabled?
  res = ""
  begin
    zipped = compiler_output.split($/).zip(error_descs)
    zipped.each do |l,desc|
      if desc.severity != 255
        coloring = {}
        if desc.severity == ErrorParser::SEVERITY_WARNING
          res << printWarning(l)
        elsif desc.severity == ErrorParser::SEVERITY_ERROR
          res << printError(l)
        else
          res << printInfo(l)
        end
      else
        res << l
      end
      res << "\n"
    end
  rescue Exception => e
    puts "Error while parsing compiler output: #{e}"
    return compiler_output
  end
  res
end
printAdditionalInfo(str) click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 55
def printAdditionalInfo(str)
  print_color_style(str, @@additional_info_color, :bold)
end
printError(str) click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 43
def printError(str)
  print_color_style(str, @@error_color, :bold)
end
printInfo(str) click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 51
def printInfo(str)
  print_color_style(str, @@info_color, :bold)
end
printSuccess(str) click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 59
def printSuccess(str)
  print_color_style(str, @@success_color, :bold)
end
printWarning(str) click to toggle source
# File lib/cxxproject/toolchain/colorizing_formatter.rb, line 47
def printWarning(str)
  print_color_style(str, @@warning_color, :bold)
end
print_color_style(str, color, style) click to toggle source