Class: Shadwire::UI
- Inherits:
-
Object
- Object
- Shadwire::UI
- Defined in:
- lib/shadwire/ui.rb
Overview
Thin terminal-and-agent-friendly IO wrapper. Output streams and the confirm behavior are injectable so commands stay decoupled from Thor and tests can capture output and answer prompts deterministically. With yes: true every confirmation is auto-accepted (the agent/CI path).
Instance Method Summary collapse
- #confirm?(question, default: false) ⇒ Boolean
- #error(message) ⇒ Object
-
#initialize(out: $stdout, err: $stderr, yes: false, confirm_proc: nil) ⇒ UI
constructor
A new instance of UI.
- #say(message) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize(out: $stdout, err: $stderr, yes: false, confirm_proc: nil) ⇒ UI
Returns a new instance of UI.
9 10 11 12 13 14 |
# File 'lib/shadwire/ui.rb', line 9 def initialize(out: $stdout, err: $stderr, yes: false, confirm_proc: nil) @out = out @err = err @yes = yes @confirm_proc = confirm_proc end |
Instance Method Details
#confirm?(question, default: false) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/shadwire/ui.rb', line 28 def confirm?(question, default: false) return true if @yes return !!@confirm_proc.call(question) if @confirm_proc prompt(question, default) end |
#error(message) ⇒ Object
24 25 26 |
# File 'lib/shadwire/ui.rb', line 24 def error() @err.puts() end |
#say(message) ⇒ Object
16 17 18 |
# File 'lib/shadwire/ui.rb', line 16 def say() @out.puts() end |
#warn(message) ⇒ Object
20 21 22 |
# File 'lib/shadwire/ui.rb', line 20 def warn() @err.puts() end |