Class: TUI::App
- Inherits:
-
Object
- Object
- TUI::App
- Defined in:
- lib/tui/app.rb
Constant Summary collapse
- SCREENS =
%i[chat].freeze
- COMMAND_KEYS =
{ "a" => :anthropic_token, "h" => :toggle_hud, "n" => :new_session, "s" => :session_picker, "v" => :view_mode, "q" => :quit }.freeze
- MENU_LABELS =
(COMMAND_KEYS.map { |key, action| "[#{key}] #{action.to_s.tr("_", " ").capitalize}" } + ["[\u2191] Scroll chat", "[\u2193] Return to input"]).freeze
- HUD_MIN_WIDTH =
HUD occupies 1/3 of screen width, clamped to a usable minimum.
24- PICKER_PREFIX_WIDTH =
Picker entry prefix width: β[N]β (3) + marker (1) + space (1) = 5
5- VIEW_MODE_LABELS =
User-facing descriptions shown below each mode name in the view mode picker.
{ "basic" => "Chat messages only", "verbose" => "Tools & timestamps", "debug" => "Full LLM context" }.freeze
- STATUS_STYLES =
Connection status emoji indicators for the info panel. Subscribed (normal state) shows only the emoji; other states add text.
{ disconnected: {label: "π΄ Disconnected", color: "red"}, connecting: {label: "π‘ Connecting", color: "yellow"}, connected: {label: "π‘ Connecting", color: "yellow"}, subscribed: {label: "π’", color: "green"}, reconnecting: {label: "π‘ Reconnecting", color: "yellow"} }.freeze
- TOKEN_MASK_VISIBLE =
Number of leading characters to show unmasked in the token input. Matches the βsk-ant-oat01-β prefix (13 chars) plus one character of the secret portion so the user can verify both the token type and start of key.
14- TOKEN_MASK_STARS =
Maximum stars to show in the masked portion of the token. Keeps the masked display compact regardless of actual token length.
4- POPUP_HEIGHT =
Token setup popup dimensions. Height accommodates: status line, blank, 2 instruction lines, blank, βToken:β label, input line, blank, error/success line, blank, hint line, plus top/bottom borders.
14- POPUP_MIN_WIDTH =
44- PRINTABLE_CHAR =
Matches a single printable Unicode character (no control codes).
/\A[[:print:]]\z/- 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.
-
#hud_visible ⇒ Boolean
readonly
True when the HUD info panel is visible.
-
#perf_logger ⇒ TUI::PerformanceLogger
readonly
Frame timing logger (no-op when debug is off).
-
#session_picker_active ⇒ Object
readonly
Returns the value of attribute session_picker_active.
-
#shutdown_requested ⇒ Boolean
readonly
True when graceful shutdown has been requested via signal.
-
#token_setup_active ⇒ Boolean
readonly
True when the token setup popup overlay is visible.
-
#view_mode_picker_active ⇒ Object
readonly
Returns the value of attribute view_mode_picker_active.
Instance Method Summary collapse
-
#initialize(cable_client:, debug: false) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
Constructor Details
#initialize(cable_client:, debug: false) ⇒ App
Returns a new instance of App.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/tui/app.rb', line 94 def initialize(cable_client:, debug: false) @cable_client = cable_client @perf_logger = PerformanceLogger.new(enabled: debug) @current_screen = :chat @command_mode = false @session_picker_active = false @session_picker_index = 0 @session_picker_page = 0 @session_picker_mode = :root @session_picker_parent_id = nil @hud_visible = true @view_mode_picker_active = false @view_mode_picker_index = 0 @token_setup_active = false @token_input_buffer = InputBuffer.new @token_setup_error = nil @token_setup_warning = nil @token_setup_status = :idle @shutdown_requested = false @previous_signal_handlers = {} @watchdog_thread = nil @screens = { chat: Screens::Chat.new(cable_client: cable_client, perf_logger: @perf_logger) } end |
Instance Attribute Details
#command_mode ⇒ Object (readonly)
Returns the value of attribute command_mode.
81 82 83 |
# File 'lib/tui/app.rb', line 81 def command_mode @command_mode end |
#current_screen ⇒ Object (readonly)
Returns the value of attribute current_screen.
81 82 83 |
# File 'lib/tui/app.rb', line 81 def current_screen @current_screen end |
#hud_visible ⇒ Boolean (readonly)
Returns true when the HUD info panel is visible.
84 85 86 |
# File 'lib/tui/app.rb', line 84 def hud_visible @hud_visible end |
#perf_logger ⇒ TUI::PerformanceLogger (readonly)
Returns frame timing logger (no-op when debug is off).
90 91 92 |
# File 'lib/tui/app.rb', line 90 def perf_logger @perf_logger end |
#session_picker_active ⇒ Object (readonly)
Returns the value of attribute session_picker_active.
81 82 83 |
# File 'lib/tui/app.rb', line 81 def session_picker_active @session_picker_active end |
#shutdown_requested ⇒ Boolean (readonly)
Returns true when graceful shutdown has been requested via signal.
88 89 90 |
# File 'lib/tui/app.rb', line 88 def shutdown_requested @shutdown_requested end |
#token_setup_active ⇒ Boolean (readonly)
Returns true when the token setup popup overlay is visible.
86 87 88 |
# File 'lib/tui/app.rb', line 86 def token_setup_active @token_setup_active end |
#view_mode_picker_active ⇒ Object (readonly)
Returns the value of attribute view_mode_picker_active.
81 82 83 |
# File 'lib/tui/app.rb', line 81 def view_mode_picker_active @view_mode_picker_active end |
Instance Method Details
#run ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tui/app.rb', line 120 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 |