class Kameleon::UI::Shell
Constants
- LEVELS
Attributes
Public Class Methods
Source
# File lib/kameleon/ui.rb, line 50 def initialize(options = {}) @shell = Thor::Base.shell.new @level = ENV['KAMELEON_DEBUG'] ? "debug" : "info" end
Public Instance Methods
Source
# File lib/kameleon/ui.rb, line 63 def confirm(msg, newline = nil) tell_me(msg, :green, newline) if level("confirm") end
Source
# File lib/kameleon/ui.rb, line 79 def debug(msg, newline = nil) tell_me("[debug] #{msg}", nil, newline) if level("debug") end
Source
# File lib/kameleon/ui.rb, line 83 def debug? # needs to be false instead of nil to be newline param to other methods level("debug") end
Source
# File lib/kameleon/ui.rb, line 71 def error(msg, newline = nil) tell_me(msg, :red, newline) if level("error") end
Source
# File lib/kameleon/ui.rb, line 55 def info(msg, newline = nil) tell_me(msg, nil, newline) if level("info") end
Source
# File lib/kameleon/ui.rb, line 101 def level(name = nil) name ? LEVELS.index(name) <= LEVELS.index(@level) : @level end
Source
# File lib/kameleon/ui.rb, line 96 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level end
Source
# File lib/kameleon/ui.rb, line 59 def msg(msg, newline = nil) tell_me(msg, :blue, newline) if level("info") end
Source
# File lib/kameleon/ui.rb, line 88 def quiet? LEVELS.index(@level) <= LEVELS.index("warn") end
Source
# File lib/kameleon/ui.rb, line 114 def silence old_level, @level = @level, "silent" yield ensure @level = old_level end
Source
# File lib/kameleon/ui.rb, line 105 def trace(e, newline = nil) msg = ["#{e.class}: #{e.message}", *e.backtrace].join("\n") if debug? tell_me(msg, nil, newline) elsif @trace STDERR.puts "#{msg}#{newline}" end end
Source
# File lib/kameleon/ui.rb, line 75 def verbose(msg, newline = nil) tell_me("[info] #{msg}", nil, newline) if level("verbose") end
Source
# File lib/kameleon/ui.rb, line 67 def warn(msg, newline = nil) tell_me(msg, :yellow, newline) if level("warn") end
Private Instance Methods
Source
# File lib/kameleon/ui.rb, line 137 def strip_leading_spaces(text) spaces = text[/\A\s+/, 0] spaces ? text.gsub(/#{spaces}/, '') : text end
Source
# File lib/kameleon/ui.rb, line 124 def tell_me(msg, color = nil, newline = nil) msg = word_wrap(msg) if newline.is_a?(Hash) && newline[:wrap] if newline.nil? if Kameleon.log_on_progress Kameleon.log_on_progress = false msg = "\n" + msg end @shell.say(msg, color) else @shell.say(msg, color, newline) end end
valimism
Source
# File lib/kameleon/ui.rb, line 142 def word_wrap(text, line_width = Thor::Shell::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" end