Class: Legion::TTY::Components::StatusBar

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/tty/components/status_bar.rb

Constant Summary collapse

SPINNER_FRAMES =
%w[| / - \\].freeze

Instance Method Summary collapse

Constructor Details

#initializeStatusBar

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', thinking: false, plan_mode: false }
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