Class: RosettAi::Ui::AccessibleTui

Inherits:
Tui
  • Object
show all
Defined in:
lib/rosett_ai/ui/accessible_tui.rb

Overview

Accessible TUI adapter for screen-reader-friendly output.

Produces linear, sequential text without box-drawing characters or ANSI escape sequences. Auto-selected when assistive technology is detected (ORCA_RUNNING, BRLTTY_TTY).

Constant Summary

Constants inherited from Base

Base::RTL_LOCALES

Instance Method Summary collapse

Methods inherited from Tui

#initialize, #prompt_user

Methods inherited from Base

#accessible?, #prompt_user, #text_direction

Constructor Details

This class inherits a constructor from RosettAi::Ui::Tui

Instance Method Details

#announce(message, priority: :polite) ⇒ void

This method returns an undefined value.

Announce a message to the user via the UI backend.

Parameters:

  • message (Object)

    the message

  • priority (Object) (defaults to: :polite)

    the priority



58
59
60
61
# File 'lib/rosett_ai/ui/accessible_tui.rb', line 58

def announce(message, priority: :polite)
  prefix = priority == :assertive ? '[ASSERTIVE]' : '[POLITE]'
  warn("#{prefix} #{message}")
end

#display_table(headers, rows) ⇒ void

This method returns an undefined value.

Render a table in the UI backend.

Parameters:

  • headers (Object)

    the headers

  • rows (Object)

    the rows



28
29
30
31
32
33
34
35
36
37
# File 'lib/rosett_ai/ui/accessible_tui.rb', line 28

def display_table(headers, rows)
  widths = compute_column_widths(headers, rows)

  header_line = format_row(headers, widths)
  separator = widths.map { |w| '-' * w }.join('  ')

  $stdout.puts(header_line)
  $stdout.puts(separator)
  rows.each { |row| $stdout.puts(format_row(row, widths)) }
end

#render(content) ⇒ void

This method returns an undefined value.

Render content in the UI backend.

Parameters:

  • content (Object)

    the content



19
20
21
# File 'lib/rosett_ai/ui/accessible_tui.rb', line 19

def render(content)
  $stdout.puts(RosettAi::TextSanitizer.strip_ansi(String(content)))
end

#show_spinner(message) ⇒ void

This method returns an undefined value.

Display a spinner during a long-running operation.

Parameters:

  • message (Object)

    the message



43
44
45
46
47
48
49
50
51
# File 'lib/rosett_ai/ui/accessible_tui.rb', line 43

def show_spinner(message)
  $stdout.puts("Processing: #{message}...")
  result = yield
  $stdout.puts('Done.')
  result
rescue StandardError => e
  $stdout.puts('Failed.')
  raise e
end