Class: Legion::TTY::Components::StatusBar
- Inherits:
-
Object
- Object
- Legion::TTY::Components::StatusBar
- Defined in:
- lib/legion/tty/components/status_bar.rb
Instance Method Summary collapse
-
#initialize ⇒ StatusBar
constructor
A new instance of StatusBar.
- #render(width:) ⇒ Object
- #update(**fields) ⇒ Object
Constructor Details
#initialize ⇒ StatusBar
Returns a new instance of StatusBar.
9 10 11 |
# File 'lib/legion/tty/components/status_bar.rb', line 9 def initialize @state = { model: nil, tokens: 0, cost: 0.0, session: 'default' } end |
Instance Method Details
#render(width:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/tty/components/status_bar.rb', line 17 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
13 14 15 |
# File 'lib/legion/tty/components/status_bar.rb', line 13 def update(**fields) @state.merge!(fields) end |