Pretty color output for the compass logger.
This commit is contained in:
parent
cc31c29807
commit
4b68a64ea9
@ -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))
|
||||
|
@ -31,7 +31,8 @@ module Compass
|
||||
:sass_options,
|
||||
:asset_host,
|
||||
:asset_cache_buster,
|
||||
:line_comments
|
||||
:line_comments,
|
||||
:color_output
|
||||
].flatten
|
||||
|
||||
end
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user