Class: RosettAi::Ui::Tui
- Inherits:
-
Base
- Object
- Base
- RosettAi::Ui::Tui
show all
- Defined in:
- lib/rosett_ai/ui/tui.rb
Overview
Terminal UI adapter using TTY gems.
Default adapter for headless and terminal environments.
Constant Summary
Constants inherited
from Base
Base::RTL_LOCALES
Instance Method Summary
collapse
Methods inherited from Base
#accessible?, #text_direction
Constructor Details
#initialize ⇒ Tui
Returns a new instance of Tui.
18
19
20
21
|
# File 'lib/rosett_ai/ui/tui.rb', line 18
def initialize
super
Rainbow.enabled = false if ENV.key?('NO_COLOR')
end
|
Instance Method Details
#announce(message) ⇒ Object
52
53
54
|
# File 'lib/rosett_ai/ui/tui.rb', line 52
def announce(message)
warn(message)
end
|
#display_table(headers, rows) ⇒ Object
27
28
29
30
|
# File 'lib/rosett_ai/ui/tui.rb', line 27
def display_table(, rows)
table = ::Terminal::Table.new(headings: , rows: rows)
$stdout.puts(table)
end
|
#prompt_user(question, choices: nil) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/rosett_ai/ui/tui.rb', line 32
def prompt_user(question, choices: nil)
prompt = TTY::Prompt.new
if choices
prompt.select(question, choices)
else
prompt.ask(question)
end
end
|
#render(content) ⇒ Object
23
24
25
|
# File 'lib/rosett_ai/ui/tui.rb', line 23
def render(content)
$stdout.puts(content)
end
|
#show_spinner(message) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/rosett_ai/ui/tui.rb', line 41
def show_spinner(message)
spinner = TTY::Spinner.new("[:spinner] #{message}", format: :dots)
spinner.auto_spin
result = yield
spinner.success(Rainbow(' done').green)
result
rescue StandardError => e
spinner.error(Rainbow(' failed').red)
raise e
end
|