Always colorize Cygwin output

This commit is contained in:
Mitchell Hashimoto 2013-04-06 16:03:25 -07:00
parent fbdd46a130
commit fb9c311b4d
3 changed files with 29 additions and 9 deletions

View File

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

View File

@ -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
else
opts[:ui_class] = Vagrant::UI::Colored
elsif !Vagrant::Util::Platform.terminal_supports_colors?
opts[:ui_class] = Vagrant::UI::Basic
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

View File

@ -67,7 +67,8 @@ module Vagrant
# 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