diff options
Diffstat (limited to 'lib/bundler/ui/shell.rb')
-rw-r--r-- | lib/bundler/ui/shell.rb | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index 17777af4ac..4555612dbb 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -20,29 +20,52 @@ module Bundler @shell.set_color(string, *color) end - def info(msg, newline = nil) - tell_me(msg, nil, newline) if level("info") + def info(msg = nil, newline = nil) + return unless info? + + tell_me(msg || yield, nil, newline) end - def confirm(msg, newline = nil) - tell_me(msg, :green, newline) if level("confirm") + def confirm(msg = nil, newline = nil) + return unless confirm? + + tell_me(msg || yield, :green, newline) end - def warn(msg, newline = nil, color = :yellow) - return unless level("warn") + def warn(msg = nil, newline = nil, color = :yellow) + return unless warn? return if @warning_history.include? msg @warning_history << msg - tell_err(msg, color, newline) + tell_err(msg || yield, color, newline) + end + + def error(msg = nil, newline = nil, color = :red) + return unless error? + + tell_err(msg || yield, color, newline) + end + + def debug(msg = nil, newline = nil) + return unless debug? + + tell_me(msg || yield, nil, newline) + end + + def info? + level("info") + end + + def confirm? + level("confirm") end - def error(msg, newline = nil, color = :red) - return unless level("error") - tell_err(msg, color, newline) + def warn? + level("warn") end - def debug(msg, newline = nil) - tell_me(msg, nil, newline) if debug? + def error? + level("error") end def debug? @@ -81,7 +104,7 @@ module Bundler def trace(e, newline = nil, force = false) return unless debug? || force msg = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}" - tell_me(msg, nil, newline) + tell_err(msg, nil, newline) end def silence(&blk) @@ -107,7 +130,7 @@ module Bundler def tell_err(message, color = nil, newline = nil) return if @shell.send(:stderr).closed? - newline ||= message.to_s !~ /( |\t)\Z/ + newline ||= !message.to_s.match?(/( |\t)\Z/) message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap] color = nil if color && !$stderr.tty? @@ -124,7 +147,7 @@ module Bundler spaces ? text.gsub(/#{spaces}/, "") : text end - def word_wrap(text, line_width = @shell.terminal_width) + def word_wrap(text, line_width = Thor::Terminal.terminal_width) strip_leading_spaces(text).split("\n").collect do |line| line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line end * "\n" |