Class: Aidp::Interfaces::TtyUI
- Inherits:
-
Object
- Object
- Aidp::Interfaces::TtyUI
show all
- Includes:
- UiInterface
- Defined in:
- lib/aidp/interfaces/ui_interface.rb
Overview
TtyUI wraps TTY::Prompt and TTY::Spinner for UI operations.
This is the standard implementation used by AIDP.
Constant Summary
collapse
- COLOR_MAP =
{
info: :blue,
success: :green,
warning: :yellow,
error: :red,
highlight: :cyan,
muted: :bright_black
}.freeze
- CRITICAL_TYPES =
[:error, :warning, :success].freeze
Constants included
from UiInterface
UiInterface::MESSAGE_TYPES
Instance Method Summary
collapse
Constructor Details
#initialize(prompt: nil, quiet: false) ⇒ TtyUI
Returns a new instance of TtyUI.
181
182
183
184
|
# File 'lib/aidp/interfaces/ui_interface.rb', line 181
def initialize(prompt: nil, quiet: false)
@prompt = prompt
@quiet = quiet
end
|
Instance Method Details
#quiet? ⇒ Boolean
212
213
214
|
# File 'lib/aidp/interfaces/ui_interface.rb', line 212
def quiet?
@quiet
end
|
#say(message, type: :info) ⇒ Object
186
187
188
189
190
|
# File 'lib/aidp/interfaces/ui_interface.rb', line 186
def say(message, type: :info)
return if @quiet && !CRITICAL_TYPES.include?(type)
prompt.say(message.to_s, color: COLOR_MAP.fetch(type, :white))
end
|
#spinner(title:) ⇒ Object
207
208
209
210
|
# File 'lib/aidp/interfaces/ui_interface.rb', line 207
def spinner(title:)
require "tty-spinner"
TtySpinnerWrapper.new(title: title)
end
|
#with_spinner(title:) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/aidp/interfaces/ui_interface.rb', line 192
def with_spinner(title:)
require "tty-spinner"
spin = TTY::Spinner.new("[:spinner] #{title}", format: :dots, hide_cursor: true)
spin.auto_spin
begin
result = yield
spin.success("done")
result
rescue
spin.error("failed")
raise
end
end
|