Class: VimDo::UI::Shell
Constant Summary collapse
- LEVELS =
%w(silent error warn confirm info debug)
Instance Attribute Summary collapse
-
#shell ⇒ Object
writeonly
Sets the attribute shell.
Instance Method Summary collapse
- #ask(msg) ⇒ Object
- #confirm(msg, newline = nil) ⇒ Object
- #debug(msg, newline = nil) ⇒ Object
- #debug? ⇒ Boolean
- #error(msg, newline = nil) ⇒ Object
- #info(msg, newline = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Shell
constructor
A new instance of Shell.
- #level(name = nil) ⇒ Object
- #level=(level) ⇒ Object
- #quiet? ⇒ Boolean
- #silence ⇒ Object
- #trace(e, newline = nil) ⇒ Object
- #warn(msg, newline = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Shell
Returns a new instance of Shell.
33 34 35 36 37 38 39 |
# File 'lib/vimdo/ui.rb', line 33 def initialize( = {}) if ["no-color"] || !STDOUT.tty? Thor::Base.shell = Thor::Shell::Basic end @shell = Thor::Base.shell.new @level = ENV['DEBUG'] ? "debug" : "info" end |
Instance Attribute Details
#shell=(value) ⇒ Object (writeonly)
Sets the attribute shell
31 32 33 |
# File 'lib/vimdo/ui.rb', line 31 def shell=(value) @shell = value end |
Instance Method Details
#ask(msg) ⇒ Object
70 71 72 |
# File 'lib/vimdo/ui.rb', line 70 def ask(msg) @shell.ask(msg) end |
#confirm(msg, newline = nil) ⇒ Object
45 46 47 |
# File 'lib/vimdo/ui.rb', line 45 def confirm(msg, newline = nil) tell_me(msg, :green, newline) if level("confirm") end |
#debug(msg, newline = nil) ⇒ Object
57 58 59 |
# File 'lib/vimdo/ui.rb', line 57 def debug(msg, newline = nil) tell_me(msg, nil, newline) if level("debug") end |
#debug? ⇒ Boolean
61 62 63 64 |
# File 'lib/vimdo/ui.rb', line 61 def debug? # needs to be false instead of nil to be newline param to other methods level("debug") end |
#error(msg, newline = nil) ⇒ Object
53 54 55 |
# File 'lib/vimdo/ui.rb', line 53 def error(msg, newline = nil) tell_me(msg, :red, newline) if level("error") end |
#info(msg, newline = nil) ⇒ Object
41 42 43 |
# File 'lib/vimdo/ui.rb', line 41 def info(msg, newline = nil) tell_me(msg, nil, newline) if level("info") end |
#level(name = nil) ⇒ Object
79 80 81 |
# File 'lib/vimdo/ui.rb', line 79 def level(name = nil) name ? LEVELS.index(name) <= LEVELS.index(@level) : @level end |
#level=(level) ⇒ Object
74 75 76 77 |
# File 'lib/vimdo/ui.rb', line 74 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level end |
#quiet? ⇒ Boolean
66 67 68 |
# File 'lib/vimdo/ui.rb', line 66 def quiet? LEVELS.index(@level) <= LEVELS.index("warn") end |
#silence ⇒ Object
92 93 94 95 96 97 |
# File 'lib/vimdo/ui.rb', line 92 def silence old_level, @level = @level, "silent" yield ensure @level = old_level end |
#trace(e, newline = nil) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/vimdo/ui.rb', line 83 def trace(e, newline = nil) msg = ["#{e.class}: #{e.}", *e.backtrace].join("\n") if debug? tell_me(msg, nil, newline) elsif @trace STDERR.puts "#{msg}#{newline}" end end |
#warn(msg, newline = nil) ⇒ Object
49 50 51 |
# File 'lib/vimdo/ui.rb', line 49 def warn(msg, newline = nil) tell_me(msg, :yellow, newline) if level("warn") end |