summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-05-23 11:23:53 +1000
committerColby Swandale <colby@taplaboratories.com>2017-05-23 11:26:15 +1000
commitac374e57e6e3da826cedf1508242118ce64a3985 (patch)
treed4b1449a86f54ef11c7ed90211157449aa19a908
parent128d304ae6a43a83ed710ef483c0a5e3e97b4ac5 (diff)
downloadbundler-ac374e57e6e3da826cedf1508242118ce64a3985.tar.gz
remove colors if printing errors to stderr without a tty available
-rw-r--r--lib/bundler/ui/shell.rb4
-rw-r--r--spec/bundler/ui/shell_spec.rb2
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 81743ede40..5d4fd76acb 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -9,7 +9,7 @@ module Bundler
attr_writer :shell
def initialize(options = {})
- if options["no-color"] || !STDOUT.tty?
+ if options["no-color"] || !$stdout.tty?
Thor::Base.shell = Thor::Shell::Basic
end
@shell = Thor::Base.shell.new
@@ -108,6 +108,8 @@ module Bundler
newline = message.to_s !~ /( |\t)\Z/ unless newline
message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap]
+ color = nil if color && !$stderr.tty?
+
buffer = @shell.send(:prepare_message, message, *color)
buffer << "\n" if newline && !message.to_s.end_with?("\n")
diff --git a/spec/bundler/ui/shell_spec.rb b/spec/bundler/ui/shell_spec.rb
index 2db2d28641..050fb9c1fb 100644
--- a/spec/bundler/ui/shell_spec.rb
+++ b/spec/bundler/ui/shell_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe Bundler::UI::Shell do
context "when stderr flag is enabled" do
before { bundle "config error_on_stderr true" }
it "prints to stderr" do
- expect { subject.error("error!!!") }.to output("\e[31merror!!!\e[0m\n").to_stderr
+ expect { subject.error("error!!!") }.to output("error!!!\n").to_stderr
end
end
end