lib/bundler/ui/shell.rb in bundler-1.15.4 vs lib/bundler/ui/shell.rb in bundler-1.16.0.pre.1

- old
+ new

@@ -1,17 +1,18 @@ # frozen_string_literal: true + require "bundler/vendored_thor" module Bundler module UI class Shell - LEVELS = %w(silent error warn confirm info debug).freeze + LEVELS = %w[silent error warn confirm info debug].freeze 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 @level = ENV["DEBUG"] ? "debug" : "info" @warning_history = [] @@ -28,17 +29,22 @@ def confirm(msg, newline = nil) tell_me(msg, :green, newline) if level("confirm") end def warn(msg, newline = nil) + return unless level("warn") return if @warning_history.include? msg @warning_history << msg - tell_me(msg, :yellow, newline) if level("warn") + + return tell_err(msg, :yellow, newline) if Bundler.feature_flag.error_on_stderr? + tell_me(msg, :yellow, newline) end def error(msg, newline = nil) - tell_me(msg, :red, newline) if level("error") + return unless level("error") + return tell_err(msg, :red, newline) if Bundler.feature_flag.error_on_stderr? + tell_me(msg, :red, newline) end def debug(msg, newline = nil) tell_me(msg, nil, newline) if debug? end @@ -101,9 +107,14 @@ @shell.say(msg, color, newline) end end def tell_err(message, color = nil, newline = nil) + 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") @shell.send(:stderr).print(buffer) @shell.send(:stderr).flush