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
|
compile sass_filename, css_filename, options
|
||||||
rescue Sass::SyntaxError => e
|
rescue Sass::SyntaxError => e
|
||||||
full_exception = Compass.configuration.environment == :development
|
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,
|
write_file(css_filename,
|
||||||
Sass::SyntaxError.exception_to_css(e, :full_exception => full_exception),
|
Sass::SyntaxError.exception_to_css(e, :full_exception => full_exception),
|
||||||
options.merge(:force => true))
|
options.merge(:force => true))
|
||||||
|
@ -31,7 +31,8 @@ module Compass
|
|||||||
:sass_options,
|
:sass_options,
|
||||||
:asset_host,
|
:asset_host,
|
||||||
:asset_cache_buster,
|
:asset_cache_buster,
|
||||||
:line_comments
|
:line_comments,
|
||||||
|
:color_output
|
||||||
].flatten
|
].flatten
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -34,6 +34,10 @@ module Compass
|
|||||||
top_level.environment == :development
|
top_level.environment == :development
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_color_output
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def default_sass_path
|
def default_sass_path
|
||||||
if (pp = top_level.project_path) && (dir = top_level.sass_dir)
|
if (pp = top_level.project_path) && (dir = top_level.sass_dir)
|
||||||
File.join(pp, dir)
|
File.join(pp, dir)
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
module Compass
|
module Compass
|
||||||
class Logger
|
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
|
attr_accessor :actions, :options
|
||||||
|
|
||||||
@ -13,9 +26,22 @@ module Compass
|
|||||||
|
|
||||||
# Record an action that has occurred
|
# Record an action that has occurred
|
||||||
def record(action, *arguments)
|
def record(action, *arguments)
|
||||||
|
emit color(ACTION_COLORS[action]) if Compass.configuration.color_output
|
||||||
log "#{action_padding(action)}#{action} #{arguments.join(' ')}"
|
log "#{action_padding(action)}#{action} #{arguments.join(' ')}"
|
||||||
|
emit color(:clear) if Compass.configuration.color_output
|
||||||
end
|
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
|
# Emit a log message
|
||||||
def log(msg)
|
def log(msg)
|
||||||
puts msg
|
puts msg
|
||||||
@ -39,4 +65,4 @@ module Compass
|
|||||||
def log(msg)
|
def log(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ module Compass::CommandLineHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
responder.assert_required_responses!
|
responder.assert_required_responses!
|
||||||
@last_result = output
|
@last_result = decolorize(output)
|
||||||
else
|
else
|
||||||
#child process
|
#child process
|
||||||
execute *arguments
|
execute *arguments
|
||||||
@ -38,15 +38,19 @@ module Compass::CommandLineHelper
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
@last_error = capture_warning do
|
@last_error = capture_warning do
|
||||||
@last_result = capture_output do
|
@last_result = decolorize(capture_output do
|
||||||
@last_exit_code = execute *arguments
|
@last_exit_code = execute *arguments
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
fail "Read from child process timed out"
|
fail "Read from child process timed out"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def decolorize(str)
|
||||||
|
str.gsub(/\e\[\d+m/,'')
|
||||||
|
end
|
||||||
|
|
||||||
class Responder
|
class Responder
|
||||||
Response = Struct.new(:prompt, :text, :required, :responded)
|
Response = Struct.new(:prompt, :text, :required, :responded)
|
||||||
def initialize
|
def initialize
|
||||||
@ -79,7 +83,7 @@ module Compass::CommandLineHelper
|
|||||||
actions_found << line.first if line.last == path
|
actions_found << line.first if line.last == path
|
||||||
end
|
end
|
||||||
message = "Action #{action.inspect} was not performed on: #{path}."
|
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
|
puts @last_result
|
||||||
fail message
|
fail message
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user