diff --git a/CHANGELOG.md b/CHANGELOG.md index d8449e95d..69e071d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ - Error message for improperly packaged box files. [GH-198] - Copy insecure private key to user-owned directory so even `sudo` installed Vagrant installations work. [GH-580] + - Provisioner stdout/stderr is now color coded based on stdout/stderr. + stdout is green, stderr is red. [GH-595] ## 0.8.10 (December 10, 2011) diff --git a/lib/vagrant/provisioners/chef_client.rb b/lib/vagrant/provisioners/chef_client.rb index 9c0620a02..b198ef36b 100644 --- a/lib/vagrant/provisioners/chef_client.rb +++ b/lib/vagrant/provisioners/chef_client.rb @@ -102,7 +102,12 @@ module Vagrant if type == :exit_status ssh.check_exit_status(data, command) else - env[:ui].info("#{data}: #{type}") + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red + + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 931a59d4d..0cb2b2c77 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -133,7 +133,12 @@ module Vagrant if type == :exit_status ssh.check_exit_status(data, command) else - env[:ui].info("#{data}: #{type}") + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red + + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index dc48c74f2..afb29fb87 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -129,7 +129,12 @@ module Vagrant if type == :exit_status ssh.check_exit_status(data, commands) else - env.ui.info(data) + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red + + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end diff --git a/lib/vagrant/provisioners/shell.rb b/lib/vagrant/provisioners/shell.rb index 50d1e1569..eea9e0e85 100644 --- a/lib/vagrant/provisioners/shell.rb +++ b/lib/vagrant/provisioners/shell.rb @@ -87,7 +87,12 @@ module Vagrant if type == :exit_status ssh.check_exit_status(data, commands) else - env[:ui].info(data) + # Output the data with the proper color based on the stream. + color = type == :stdout ? :green : :red + + # Note: Be sure to chomp the data to avoid the newlines that the + # Chef outputs. + env[:ui].info(data.chomp, :color => color, :prefix => false) end end end diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 6eb00b3af..69019a0b0 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -99,16 +99,18 @@ module Vagrant # but is up to the user of the class to verify this is the case. class Colored < Basic # Terminal colors - CLEAR = "\e[0m" - YELLOW = "\e[33m" - RED = "\e[31m" - GREEN = "\e[32m" + COLORS = { + :clear => "\e[0m", + :red => "\e[31m", + :green => "\e[32m", + :yellow => "\e[33m" + } # Mapping between type of message and the color to output COLOR_MAP = { - :warn => YELLOW, - :error => RED, - :success => GREEN + :warn => COLORS[:yellow], + :error => COLORS[:red], + :success => COLORS[:green] } # This is called by `say` to format the message for output. @@ -116,8 +118,15 @@ module Vagrant # Get the format of the message before adding color. message = super - # Colorize the message if there is a color for this type of message - message = "#{COLOR_MAP[type]}#{message}#{CLEAR}" if COLOR_MAP[type] + # Colorize the message if there is a color for this type of message, + # either specified by the options or via the default color map. + if opts.has_key?(:color) + color = COLORS[opts[:color]] + message = "#{color}#{message}#{COLORS[:clear]}" + else + message = "#{COLOR_MAP[type]}#{message}#{COLORS[:clear]}" if COLOR_MAP[type] + end + message end end