Skip to content

Commit

Permalink
Always colorize Cygwin output
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 6, 2013
1 parent fbdd46a commit fb9c311
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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)

Expand Down
31 changes: 23 additions & 8 deletions bin/vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant/util/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb9c311

Please sign in to comment.