Do not output color if stdout is not a TTY

This commit is contained in:
Mitchell Hashimoto 2011-11-02 21:59:35 -07:00
parent 2bd0b76fd2
commit d753b750e9
3 changed files with 20 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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