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 } @notifications = [] end |
Instance Method Details
#notify(message:, level: :info, ttl: 5) ⇒ Object
17 18 19 |
# File 'lib/legion/tty/components/status_bar.rb', line 17 def notify(message:, level: :info, ttl: 5) @notifications << Notification.new(message: , level: level, ttl: ttl) end |
#render(width:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/legion/tty/components/status_bar.rb', line 25 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
21 22 23 |
# File 'lib/legion/tty/components/status_bar.rb', line 21 def update(**fields) @state.merge!(fields) end |