From d753b750e91ed4cf140309b043edbbcec1a41cee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 2 Nov 2011 21:59:35 -0700 Subject: [PATCH] Do not output color if stdout is not a TTY --- CHANGELOG.md | 2 ++ bin/vagrant | 7 ++++++- test/acceptance/vagrant_test.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/vagrant_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f4c11e0..416505938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Support for basic HTTP auth in the URL for boxes. - Solaris support for host only networks. [GH-533] - `vagrant init` respects `Vagrant::Environment` cwd. [GH-528] + - `vagrant` commands will not output color when stdout is + not a TTY. ## 0.8.7 (September 13, 2011) diff --git a/bin/vagrant b/bin/vagrant index 707a2a12a..714d00936 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -9,7 +9,12 @@ begin env.logger.info("vagrant") { "`vagrant` invoked: #{ARGV.inspect}" } # Disable color if the proper argument was passed - shell = ARGV.include?("--no-color") ? Thor::Shell::Basic.new : Thor::Base.shell.new + shell = nil + if !$stdout.tty? || ARGV.include?("--no-color") + shell = Thor::Shell::Basic.new + else + shell = Thor::Base.shell.new + end # Set the UI early in case any errors are raised, and load # the config immediately, so we gather any new commands from diff --git a/test/acceptance/vagrant_test.rb b/test/acceptance/vagrant_test.rb new file mode 100644 index 000000000..419d82cb4 --- /dev/null +++ b/test/acceptance/vagrant_test.rb @@ -0,0 +1,12 @@ +require File.expand_path("../base", __FILE__) + +class VagrantTest < AcceptanceTest + should "not output color in the absense of a TTY" do + # This should always output an erorr, which on a TTY would + # output color. We check that this doesn't output color. + # If `vagrant status` itself is broken, another acceptance test + # should catch that. We just assume it works here. + result = execute("vagrant", "status") + assert(result.stdout.read !~ /\e\[31/, "output should not contain color") + end +end