Class: Shadwire::UI

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (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(message)
  @err.puts(message)
end

#say(message) ⇒ Object



16
17
18
# File 'lib/shadwire/ui.rb', line 16

def say(message)
  @out.puts(message)
end

#warn(message) ⇒ Object



20
21
22
# File 'lib/shadwire/ui.rb', line 20

def warn(message)
  @err.puts(message)
end