From fb9c311b4d6a2853b46ce1bbe1564673a056862b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 6 Apr 2013 16:03:25 -0700 Subject: [PATCH] Always colorize Cygwin output --- CHANGELOG.md | 4 ++++ bin/vagrant | 31 +++++++++++++++++++++++-------- lib/vagrant/util/platform.rb | 3 ++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 972472ef5a4..64de811a43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ FEATURES: IMPROVEMENTS: + - Full Windows support in cmd.exe, PowerShell, Cygwin, and MingW based + environments. - By adding the "disabled" boolean flag to synced folders you can disable them altogether. [GH-1004] - Specify the default provider with the `VAGRANT_DEFAULT_PROVIDER` @@ -45,6 +47,8 @@ BUG FIXES: - Don't preserve modified time when untarring boxes. [GH-1539] - Forwarded port auto-correct will not auto-correct to a port that is also in use. + - Cygwin will always output color by default. Specify `--no-color` to + override this. ## 1.1.6 (April 3, 2013) diff --git a/bin/vagrant b/bin/vagrant index 895e2c16049..04e16816ed6 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -22,18 +22,33 @@ $stderr.sync = true # environment. opts = {} -# Disable color if the proper argument was passed or if we're -# on Windows since the default Windows terminal doesn't support -# colors. -if ARGV.include?("--no-color") || !$stdout.tty? || !Vagrant::Util::Platform.terminal_supports_colors? - # Delete the argument from the list so that it doesn't cause any - # invalid arguments down the road. +# Disable color in a few cases: +# +# * --no-color is anywhere in our arguments +# * STDOUT is not a TTY +# * The terminal doesn't support colors (Windows) +# +if ARGV.include?("--no-color") + # Delete the argument from the list so that it doesn't + # cause any invalid arguments down the road. ARGV.delete("--no-color") + + opts[:ui_class] = Vagrant::UI::Basic +elsif !Vagrant::Util::Platform.terminal_supports_colors? opts[:ui_class] = Vagrant::UI::Basic -else - opts[:ui_class] = Vagrant::UI::Colored +elsif !$stdout.tty? + # If we're not a TTY, verify we're not in Cygwin. Cygwin always + # reports that stdout is not a TTY, when in fact it is. + ENV["VAGRANT_DETECTED_OS"] ||= "" + + if !ENV["VAGRANT_DETECTED_OS"].downcase.include?("cygwin") + opts[:ui_class] = Vagrant::UI::Basic + end end +# Default to colored output +opts[:ui_class] ||= Vagrant::UI::Colored + # This is kind of hacky, and I'd love to find a better way to do this, but # if we're accessing the plugin interface, we want to NOT load plugins # for this run, because they can actually interfere with the function diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 44a4b0a63c2..d8f626012ef 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -67,7 +67,8 @@ def platform_path(path) # output. def terminal_supports_colors? if windows? - return ENV.has_key?("ANSICON") + return ENV.has_key?("ANSICON") || + ENV["VAGRANT_DETECTED_OS"].downcase.include?("cygwin") end true