Class: Bake::ColorizingFormatter
- Inherits:
-
Object
- Object
- Bake::ColorizingFormatter
- Defined in:
- lib/bake/toolchain/colorizing_formatter.rb
Overview
include Utils ????
Instance Method Summary collapse
- #createIdeError(str, file_name, line_number, severity) ⇒ Object
-
#format(compiler_output, error_descs, error_parser) ⇒ Object
formats several lines of compiler output.
-
#initialize ⇒ ColorizingFormatter
constructor
A new instance of ColorizingFormatter.
- #printAdditionalInfo(str) ⇒ Object
- #printError(str, file_name_or_elem = nil, line_num = nil) ⇒ Object
- #printInfo(str, file_name = nil, line_num = nil) ⇒ Object
- #printInternal(col, str) ⇒ Object
- #printSuccess(str) ⇒ Object
- #printWarning(str, file_name = nil, line_num = nil) ⇒ Object
- #processString(prefix, str, file_name_or_elem, line_num, severity) ⇒ Object
- #setColorScheme(scheme) ⇒ Object
Constructor Details
#initialize ⇒ ColorizingFormatter
Returns a new instance of ColorizingFormatter.
8 9 10 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 8 def initialize @scheme = :none end |
Instance Method Details
#createIdeError(str, file_name, line_number, severity) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 39 def createIdeError(str, file_name, line_number, severity) if (file_name) d = ErrorDesc.new d.file_name = file_name d.line_number = (line_number ? line_number : 0) d. = str d.severity = severity Bake::IDEInterface.instance.set_errors([d]) end end |
#format(compiler_output, error_descs, error_parser) ⇒ Object
formats several lines of compiler output
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 91 def format(compiler_output, error_descs, error_parser) if @scheme == :none puts compiler_output else begin zipped = compiler_output.split($/).zip(error_descs) zipped.each do |l,desc| if desc.severity != 255 coloring = {} if desc.severity == ErrorParser::SEVERITY_WARNING printWarning(l) elsif desc.severity == ErrorParser::SEVERITY_ERROR printError(l) else printInfo(l) end else puts l end end rescue Exception => e puts "Error while parsing output: #{e}" puts e.backtrace if Bake..debug puts compiler_output end end end |
#printAdditionalInfo(str) ⇒ Object
82 83 84 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 82 def printAdditionalInfo(str) printInternal(@additional_info_color, str) end |
#printError(str, file_name_or_elem = nil, line_num = nil) ⇒ Object
67 68 69 70 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 67 def printError(str, file_name_or_elem=nil, line_num=nil) str = processString("Error", str, file_name_or_elem, line_num, Bake::ErrorParser::SEVERITY_ERROR) if file_name_or_elem printInternal(@error_color, str) end |
#printInfo(str, file_name = nil, line_num = nil) ⇒ Object
77 78 79 80 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 77 def printInfo(str, file_name=nil, line_num=nil) str = processString("Info", str, file_name, line_num, Bake::ErrorParser::SEVERITY_INFO) if file_name printInternal(@info_color, str) end |
#printInternal(col, str) ⇒ Object
35 36 37 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 35 def printInternal(col, str) puts(@scheme == :none ? str : [col,:bold].inject(str) {|m,x| m.send(x)}) end |
#printSuccess(str) ⇒ Object
86 87 88 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 86 def printSuccess(str) printInternal(@success_color, str) end |
#printWarning(str, file_name = nil, line_num = nil) ⇒ Object
72 73 74 75 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 72 def printWarning(str, file_name=nil, line_num=nil) str = processString("Warning", str, file_name, line_num, Bake::ErrorParser::SEVERITY_WARNING) if file_name printInternal(@warning_color, str) end |
#processString(prefix, str, file_name_or_elem, line_num, severity) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 50 def processString(prefix, str, file_name_or_elem, line_num, severity) if file_name_or_elem.respond_to?("file_name") file_name = file_name_or_elem.file_name line_num = file_name_or_elem.line_number elsif String === file_name_or_elem file_name = file_name_or_elem else file_name = nil end createIdeError(str, file_name, line_num, severity) line = (line_num ? ":#{line_num}" : "") file = (file_name ? "#{file_name}#{line}: " : "") return file + prefix + ": " + str end |
#setColorScheme(scheme) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bake/toolchain/colorizing_formatter.rb', line 12 def setColorScheme(scheme) if (scheme != :black and scheme != :white and scheme != :none) Bake.formatter.printError("Error: color scheme must be 'black', 'white' or 'none'") ExitHelper.exit(1) end @scheme = 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 |