Class: TUI::App
- Inherits:
-
Object
- Object
- TUI::App
- Defined in:
- lib/tui/app.rb
Constant Summary collapse
- SCREENS =
%i[chat].freeze
- COMMAND_KEYS =
{ "n" => :new_session, "v" => :view_mode, "q" => :quit }.freeze
- MENU_LABELS =
COMMAND_KEYS.map { |key, action| "[#{key}] #{action.to_s.tr("_", " ").capitalize}" }.freeze
- SIDEBAR_WIDTH =
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
- SHUTDOWN_SIGNALS =
Signals that trigger graceful shutdown when received from the OS.
%w[HUP TERM INT].freeze
- TERMINAL_CHECK_INTERVAL =
How often the watchdog thread checks if the controlling terminal is alive.
0.5- CONTROLLING_TERMINAL =
Unix controlling terminal device path.
"/dev/tty"- WATCHDOG_SHUTDOWN_TIMEOUT =
Grace period for watchdog thread to exit before force-killing it.
1
Instance Attribute Summary collapse
-
#command_mode ⇒ Object
readonly
Returns the value of attribute command_mode.
-
#current_screen ⇒ Object
readonly
Returns the value of attribute current_screen.
-
#shutdown_requested ⇒ Boolean
readonly
True when graceful shutdown has been requested via signal.
Instance Method Summary collapse
-
#initialize(cable_client:) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
Constructor Details
#initialize(cable_client:) ⇒ App
Returns a new instance of App.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tui/app.rb', line 49 def initialize(cable_client:) @cable_client = cable_client @current_screen = :chat @command_mode = false @shutdown_requested = false @previous_signal_handlers = {} @watchdog_thread = nil @screens = { chat: Screens::Chat.new(cable_client: cable_client) } end |
Instance Attribute Details
#command_mode ⇒ Object (readonly)
Returns the value of attribute command_mode.
44 45 46 |
# File 'lib/tui/app.rb', line 44 def command_mode @command_mode end |
#current_screen ⇒ Object (readonly)
Returns the value of attribute current_screen.
44 45 46 |
# File 'lib/tui/app.rb', line 44 def current_screen @current_screen end |
#shutdown_requested ⇒ Boolean (readonly)
Returns true when graceful shutdown has been requested via signal.
46 47 48 |
# File 'lib/tui/app.rb', line 46 def shutdown_requested @shutdown_requested end |
Instance Method Details
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tui/app.rb', line 61 def run install_signal_handlers start_terminal_watchdog RatatuiRuby.run do |tui| loop do break if @shutdown_requested tui.draw { |frame| render(frame, tui) } event = tui.poll_event(timeout: 0.1) break if @shutdown_requested next if event.nil? || event.none? break if handle_event(event) == :quit end end ensure stop_terminal_watchdog restore_signal_handlers @cable_client.disconnect end |