Class: SwarmCLI::V3::ActivityIndicator
- Inherits:
-
Object
- Object
- SwarmCLI::V3::ActivityIndicator
- Defined in:
- lib/swarm_cli/v3/activity_indicator.rb
Overview
Renders the activity indicator above the separator line.
Three states: :idle, :working, :done.
-
idle — nothing rendered, #footer_lines is 0.
-
working — breathing “Working…” animation, ticker thread running. Optionally shows a status suffix (e.g. “🧠 retrieval (133ms)”).
-
done — static “Done (Xs)” message, no ticker. Stays in the footer until the next #start call clears it.
The state machine:
idle → start → working → stop → done → start → working …
Constant Summary collapse
- TICK_INTERVAL =
0.15
Instance Attribute Summary collapse
-
#status ⇒ void
writeonly
Set a status suffix shown on the working line.
Instance Method Summary collapse
-
#footer_lines ⇒ Integer
Number of extra footer lines this indicator contributes.
-
#initialize(on_tick: nil) ⇒ ActivityIndicator
constructor
A new instance of ActivityIndicator.
-
#render ⇒ String?
Render the indicator line for the current state.
-
#start ⇒ void
Begin the working state and start the ticker thread.
-
#stop ⇒ void
End the working state and transition to done.
-
#visible? ⇒ Boolean
True if indicator occupies footer space (working or done).
-
#working? ⇒ Boolean
True if currently in the working state.
Constructor Details
#initialize(on_tick: nil) ⇒ ActivityIndicator
Returns a new instance of ActivityIndicator.
30 31 32 33 34 35 36 37 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 30 def initialize(on_tick: nil) @on_tick = on_tick @state = :idle @work_start_time = nil @done_elapsed = nil @status = nil @ticker_thread = nil end |
Instance Attribute Details
#status=(value) ⇒ void (writeonly)
This method returns an undefined value.
Set a status suffix shown on the working line.
72 73 74 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 72 def status=(value) @status = value end |
Instance Method Details
#footer_lines ⇒ Integer
Number of extra footer lines this indicator contributes.
99 100 101 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 99 def @state == :idle ? 0 : 2 end |
#render ⇒ String?
Render the indicator line for the current state.
87 88 89 90 91 92 93 94 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 87 def render case @state when :working render_working when :done render_done end end |
#start ⇒ void
This method returns an undefined value.
Begin the working state and start the ticker thread.
Transitions from any state (idle or done) to working.
44 45 46 47 48 49 50 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 44 def start @done_elapsed = nil @status = nil @work_start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @state = :working start_ticker end |
#stop ⇒ void
This method returns an undefined value.
End the working state and transition to done.
The done state keeps the indicator visible in the footer with elapsed time until the next #start call.
58 59 60 61 62 63 64 65 66 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 58 def stop return unless @state == :working stop_ticker @done_elapsed = elapsed_seconds @state = :done @status = nil @work_start_time = nil end |
#visible? ⇒ Boolean
Returns true if indicator occupies footer space (working or done).
80 81 82 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 80 def visible? @state != :idle end |
#working? ⇒ Boolean
Returns true if currently in the working state.
75 76 77 |
# File 'lib/swarm_cli/v3/activity_indicator.rb', line 75 def working? @state == :working end |