Class: RosettAi::Ui::Base

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

Overview

Abstract interface for UI implementations.

All UI adapters (TUI, GTK4, Qt6) must inherit from this class and implement the required methods. The shared example 'a UI implementation' verifies conformance.

Direct Known Subclasses

Gtk4, Kde, Qt6, Tui

Constant Summary collapse

RTL_LOCALES =

Returns Rtl locales constant.

Returns:

  • (Array)

    Rtl locales constant.

['ar', 'he', 'fa', 'ur'].freeze

Instance Method Summary collapse

Instance Method Details

#accessible?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rosett_ai/ui/base.rb', line 37

def accessible?
  ENV.key?('ORCA_RUNNING') || ENV.key?('BRLTTY_TTY')
end

#announce(message) ⇒ Object

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/rosett_ai/ui/base.rb', line 33

def announce(message)
  raise NotImplementedError, "#{self.class}#announce not implemented"
end

#display_table(headers, rows) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/rosett_ai/ui/base.rb', line 21

def display_table(headers, rows)
  raise NotImplementedError, "#{self.class}#display_table not implemented"
end

#prompt_user(question, choices: nil) ⇒ Object

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/rosett_ai/ui/base.rb', line 25

def prompt_user(question, choices: nil)
  raise NotImplementedError, "#{self.class}#prompt_user not implemented"
end

#render(content) ⇒ Object

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/rosett_ai/ui/base.rb', line 17

def render(content)
  raise NotImplementedError, "#{self.class}#render not implemented"
end

#show_spinner(message) ⇒ Object

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/rosett_ai/ui/base.rb', line 29

def show_spinner(message, &)
  raise NotImplementedError, "#{self.class}#show_spinner not implemented"
end

#text_direction(locale = nil) ⇒ Symbol

Return the text direction for the current locale.

Returns:

  • (Symbol)


43
44
45
46
# File 'lib/rosett_ai/ui/base.rb', line 43

def text_direction(locale = nil)
  lang = locale || ENV.fetch('LANG', 'en')[0, 2]
  RTL_LOCALES.include?(lang) ? :rtl : :ltr
end