Class: RosettAi::Ui::Tui
Overview
Terminal UI adapter using TTY gems.
Default adapter for headless and terminal environments.
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#announce(message) ⇒ void
Announce a message to the user via the UI backend.
-
#display_table(headers, rows) ⇒ void
Render a table in the UI backend.
-
#initialize ⇒ Tui
constructor
A new instance of Tui.
-
#prompt_user(question, choices: nil) ⇒ String
Prompt the user for interactive input.
-
#render(content) ⇒ void
Render content in the UI backend.
-
#show_spinner(message) ⇒ void
Display a spinner during a long-running operation.
Methods inherited from Base
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) ⇒ void
This method returns an undefined value.
Announce a message to the user via the UI backend.
74 75 76 |
# File 'lib/rosett_ai/ui/tui.rb', line 74 def announce() warn() end |
#display_table(headers, rows) ⇒ void
This method returns an undefined value.
Render a table in the UI backend.
36 37 38 39 |
# File 'lib/rosett_ai/ui/tui.rb', line 36 def display_table(headers, rows) table = ::Terminal::Table.new(headings: headers, rows: rows) $stdout.puts(table) end |
#prompt_user(question, choices: nil) ⇒ String
Prompt the user for interactive input.
46 47 48 49 50 51 52 53 |
# File 'lib/rosett_ai/ui/tui.rb', line 46 def prompt_user(question, choices: nil) prompt = TTY::Prompt.new if choices prompt.select(question, choices) else prompt.ask(question) end end |
#render(content) ⇒ void
This method returns an undefined value.
Render content in the UI backend.
27 28 29 |
# File 'lib/rosett_ai/ui/tui.rb', line 27 def render(content) $stdout.puts(content) end |
#show_spinner(message) ⇒ void
This method returns an undefined value.
Display a spinner during a long-running operation.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rosett_ai/ui/tui.rb', line 59 def show_spinner() spinner = TTY::Spinner.new("[:spinner] #{}", format: :dots) spinner.auto_spin result = yield spinner.success(Rainbow(' done').green) result rescue StandardError => e spinner.error(Rainbow(' failed').red) raise e end |