Class: TapDance::UI::Shell
- Inherits:
-
TapDance::UI
- Object
- TapDance::UI
- TapDance::UI::Shell
- Defined in:
- lib/tap_dance/ui.rb
Direct Known Subclasses
Constant Summary collapse
- LEVELS =
%w(silent error warn detail confirm info debug)
Instance Attribute Summary collapse
-
#shell ⇒ Object
writeonly
Sets the attribute shell.
Attributes inherited from TapDance::UI
Instance Method Summary collapse
- #ask(msg) ⇒ Object
- #confirm(msg, newline = nil) ⇒ Object
- #debug(msg, newline = nil) ⇒ Object
- #debug? ⇒ Boolean
- #detail(msg, newline = nil) ⇒ Object
- #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.
40 41 42 43 44 45 46 |
# File 'lib/tap_dance/ui.rb', line 40 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
38 39 40 |
# File 'lib/tap_dance/ui.rb', line 38 def shell=(value) @shell = value end |
Instance Method Details
#ask(msg) ⇒ Object
81 82 83 |
# File 'lib/tap_dance/ui.rb', line 81 def ask(msg) @shell.ask(msg) end |
#confirm(msg, newline = nil) ⇒ Object
52 53 54 |
# File 'lib/tap_dance/ui.rb', line 52 def confirm(msg, newline = nil) tell_me(msg, :green, newline) if level("confirm") end |
#debug(msg, newline = nil) ⇒ Object
68 69 70 |
# File 'lib/tap_dance/ui.rb', line 68 def debug(msg, newline = nil) tell_me(msg, nil, newline) if level("debug") end |
#debug? ⇒ Boolean
72 73 74 75 |
# File 'lib/tap_dance/ui.rb', line 72 def debug? # needs to be false instead of nil to be newline param to other methods level("debug") end |
#detail(msg, newline = nil) ⇒ Object
56 57 58 |
# File 'lib/tap_dance/ui.rb', line 56 def detail(msg, newline = nil) tell_me(msg, :cyan, newline) if level("detail") end |
#error(msg, newline = nil) ⇒ Object
64 65 66 |
# File 'lib/tap_dance/ui.rb', line 64 def error(msg, newline = nil) tell_me(msg, :red, newline) if level("error") end |
#info(msg, newline = nil) ⇒ Object
48 49 50 |
# File 'lib/tap_dance/ui.rb', line 48 def info(msg, newline = nil) tell_me(msg, nil, newline) if level("info") end |
#level(name = nil) ⇒ Object
90 91 92 |
# File 'lib/tap_dance/ui.rb', line 90 def level(name = nil) name ? LEVELS.index(name) <= LEVELS.index(@level) : @level end |
#level=(level) ⇒ Object
85 86 87 88 |
# File 'lib/tap_dance/ui.rb', line 85 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level end |
#quiet? ⇒ Boolean
77 78 79 |
# File 'lib/tap_dance/ui.rb', line 77 def quiet? LEVELS.index(@level) <= LEVELS.index("warn") end |
#silence ⇒ Object
103 104 105 106 107 108 |
# File 'lib/tap_dance/ui.rb', line 103 def silence old_level, @level = @level, "silent" yield ensure @level = old_level end |
#trace(e, newline = nil) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/tap_dance/ui.rb', line 94 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
60 61 62 |
# File 'lib/tap_dance/ui.rb', line 60 def warn(msg, newline = nil) tell_me(msg, :yellow, newline) if level("warn") end |