diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index 24f5c139..b791471e 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -52,7 +52,7 @@ module Compass compile sass_filename, css_filename, options rescue Sass::SyntaxError => e full_exception = Compass.configuration.environment == :development - logger.record :error, basename(sass_filename) + logger.record :error, basename(sass_filename), "(Line #{e.sass_line}: #{e.message})" write_file(css_filename, Sass::SyntaxError.exception_to_css(e, :full_exception => full_exception), options.merge(:force => true)) diff --git a/lib/compass/configuration.rb b/lib/compass/configuration.rb index 1999c0c5..25c300b5 100644 --- a/lib/compass/configuration.rb +++ b/lib/compass/configuration.rb @@ -31,7 +31,8 @@ module Compass :sass_options, :asset_host, :asset_cache_buster, - :line_comments + :line_comments, + :color_output ].flatten end diff --git a/lib/compass/configuration/defaults.rb b/lib/compass/configuration/defaults.rb index 54a5c43a..d511d869 100644 --- a/lib/compass/configuration/defaults.rb +++ b/lib/compass/configuration/defaults.rb @@ -34,6 +34,10 @@ module Compass top_level.environment == :development end + def default_color_output + true + end + def default_sass_path if (pp = top_level.project_path) && (dir = top_level.sass_dir) File.join(pp, dir) diff --git a/lib/compass/logger.rb b/lib/compass/logger.rb index d48eecaf..c5cb6801 100644 --- a/lib/compass/logger.rb +++ b/lib/compass/logger.rb @@ -1,7 +1,20 @@ module Compass class Logger - DEFAULT_ACTIONS = [:directory, :exists, :remove, :create, :overwrite, :compile] + DEFAULT_ACTIONS = [:directory, :exists, :remove, :create, :overwrite, :compile, :error, :identical] + + ACTION_COLORS = { + :error => :red, + :compile => :green, + :overwrite => :yellow, + :create => :green, + :remove => :yellow, + :exists => :green, + :directory => :green, + :identical => :green + } + + COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } attr_accessor :actions, :options @@ -13,9 +26,22 @@ module Compass # Record an action that has occurred def record(action, *arguments) + emit color(ACTION_COLORS[action]) if Compass.configuration.color_output log "#{action_padding(action)}#{action} #{arguments.join(' ')}" + emit color(:clear) if Compass.configuration.color_output end + def color(c) + if c && COLORS.has_key?(c.to_sym) + "\e[#{COLORS[c.to_sym]}m" + else + "" + end + end + + def emit(msg) + print msg + end # Emit a log message def log(msg) puts msg @@ -39,4 +65,4 @@ module Compass def log(msg) end end -end \ No newline at end of file +end diff --git a/test/command_line_helper.rb b/test/command_line_helper.rb index 3fc48bd6..a3363aa4 100644 --- a/test/command_line_helper.rb +++ b/test/command_line_helper.rb @@ -30,7 +30,7 @@ module Compass::CommandLineHelper end end responder.assert_required_responses! - @last_result = output + @last_result = decolorize(output) else #child process execute *arguments @@ -38,15 +38,19 @@ module Compass::CommandLineHelper end else @last_error = capture_warning do - @last_result = capture_output do + @last_result = decolorize(capture_output do @last_exit_code = execute *arguments - end + end) end end rescue Timeout::Error fail "Read from child process timed out" end + def decolorize(str) + str.gsub(/\e\[\d+m/,'') + end + class Responder Response = Struct.new(:prompt, :text, :required, :responded) def initialize @@ -79,7 +83,7 @@ module Compass::CommandLineHelper actions_found << line.first if line.last == path end message = "Action #{action.inspect} was not performed on: #{path}." - message += "The following actions were performed: #{actions_found.join(", ")}" if actions_found.any? + message += "The following actions were performed: #{actions_found.map{|a|a.inspect}.join(", ")}" if actions_found.any? puts @last_result fail message end