Class: Legion::TTY::Components::StatusBar
- Inherits:
-
Object
- Object
- Legion::TTY::Components::StatusBar
- Defined in:
- lib/legion/tty/components/status_bar.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- SPINNER_FRAMES =
%w[| / - \\].freeze
Instance Method Summary collapse
-
#initialize ⇒ StatusBar
constructor
A new instance of StatusBar.
- #notify(message:, level: :info, ttl: 5) ⇒ Object
- #render(width:) ⇒ Object
- #update(**fields) ⇒ Object
Constructor Details
#initialize ⇒ StatusBar
Returns a new instance of StatusBar.
11 12 13 14 15 |
# File 'lib/legion/tty/components/status_bar.rb', line 11 def initialize @state = { model: nil, tokens: 0, cost: 0.0, session: 'default', thinking: false, plan_mode: false, debug_mode: false, message_count: 0, multiline: false, silent: false } @notifications = [] end |
Instance Method Details
#notify(message:, level: :info, ttl: 5) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/legion/tty/components/status_bar.rb', line 17 def notify(message:, level: :info, ttl: 5) priority = level_to_priority(level) return if priority != :urgent && !Legion::TTY::NotificationGate.should_deliver?(priority: priority) @notifications << Notification.new(message: , level: level, ttl: ttl) end |
#render(width:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/legion/tty/components/status_bar.rb', line 28 def render(width:) segments = build_segments separator = Theme.c(:muted, ' | ') line = segments.join(separator) plain_length = strip_ansi(line).length if plain_length < width line + (' ' * (width - plain_length)) else truncate_to_width(line, width) end end |
#update(**fields) ⇒ Object
24 25 26 |
# File 'lib/legion/tty/components/status_bar.rb', line 24 def update(**fields) @state.merge!(fields) end |