Class: TUI::App

Inherits:
Object
  • Object
show all
Defined in:
lib/tui/app.rb

Constant Summary collapse

SCREENS =
%i[chat settings anthropic].freeze
COMMAND_KEYS =
{
  "n" => :new_session,
  "s" => :settings,
  "a" => :anthropic,
  "q" => :quit
}.freeze
COMMAND_KEYS.map { |key, action| "[#{key}] #{action.capitalize}" }.freeze
28
STATUS_STYLES =

Connection status display styles

{
  disconnected: {label: " DISCONNECTED ", fg: "white", bg: "red"},
  connecting: {label: " CONNECTING ", fg: "black", bg: "yellow"},
  connected: {label: " CONNECTED ", fg: "black", bg: "yellow"},
  subscribed: {label: " CONNECTED ", fg: "black", bg: "green"},
  reconnecting: {label: " RECONNECTING ", fg: "black", bg: "yellow"}
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cable_client:) ⇒ App

Returns a new instance of App.

Parameters:



36
37
38
39
40
41
42
43
44
45
# File 'lib/tui/app.rb', line 36

def initialize(cable_client:)
  @cable_client = cable_client
  @current_screen = :chat
  @command_mode = false
  @screens = {
    chat: Screens::Chat.new(cable_client: cable_client),
    settings: Screens::Settings.new,
    anthropic: Screens::Anthropic.new
  }
end

Instance Attribute Details

#command_modeObject (readonly)

Returns the value of attribute command_mode.



33
34
35
# File 'lib/tui/app.rb', line 33

def command_mode
  @command_mode
end

#current_screenObject (readonly)

Returns the value of attribute current_screen.



33
34
35
# File 'lib/tui/app.rb', line 33

def current_screen
  @current_screen
end

Instance Method Details

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tui/app.rb', line 47

def run
  RatatuiRuby.run do |tui|
    loop do
      tui.draw { |frame| render(frame, tui) }

      event = tui.poll_event(timeout: 0.1)
      next if event.nil? || event.none?
      break if handle_event(event) == :quit
    end
  end
ensure
  @cable_client.disconnect
end