Class: Clacky::RichUI::RichStatusView
- Inherits:
-
Object
- Object
- Clacky::RichUI::RichStatusView
- Defined in:
- lib/clacky/rich_ui/components/status_view.rb
Constant Summary collapse
- SPINNER =
['|', '/', '-', '\\'].freeze
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(shell) ⇒ RichStatusView
constructor
A new instance of RichStatusView.
- #render ⇒ Object
Constructor Details
#initialize(shell) ⇒ RichStatusView
Returns a new instance of RichStatusView.
12 13 14 15 16 17 |
# File 'lib/clacky/rich_ui/components/status_view.rb', line 12 def initialize(shell) @shell = shell @spinner_index = 0 @width = 0 @height = 1 end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
10 11 12 |
# File 'lib/clacky/rich_ui/components/status_view.rb', line 10 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
10 11 12 |
# File 'lib/clacky/rich_ui/components/status_view.rb', line 10 def width @width end |
Instance Method Details
#render ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/clacky/rich_ui/components/status_view.rb', line 19 def render theme = @shell.theme clacky = @shell.clacky_controller return [""] unless clacky status = clacky.status || "idle" tasks = clacky.tasks_count || 0 cost = clacky.total_cost || 0.0 turn = clacky.turn_active ctrlc = clacky.ctrl_c_warning mode = clacky.config&.dig(:mode) || "agent" model = clacky.config&.dig(:model) || "—" latency = clacky.latest_latency model_str = latency ? "#{model} (#{latency})" : model = "#{mode} · #{model_str}" if ctrlc line = "#{theme.style("⏎", :error)} #{theme.style(ctrlc, :error)}" elsif turn @spinner_index = (@spinner_index + 1) % SPINNER.length spinner = theme.style(SPINNER[@spinner_index], :accent) label = clacky.work_label || "working…" right = "#{} · #{tasks} tasks · $#{cost.round(4)}" left = "#{spinner} #{theme.style(label, :body)}" else right = "#{} · #{tasks} tasks · $#{cost.round(4)} · Ctrl+C quit" left = theme.style(status || "idle", :accent) end space = [@width - visible_len(left) - visible_len(right) - 2, 1].max line = "#{left}#{" " * space}#{theme.style(right, :muted)}" [line] end |