Class: Aidp::Harness::UI::SpinnerHelper
- Inherits:
-
Object
- Object
- Aidp::Harness::UI::SpinnerHelper
- Defined in:
- lib/aidp/harness/ui/spinner_helper.rb
Overview
Unified spinner helper that automatically manages TTY::Spinner lifecycle Usage: with_spinner(“Loading…”) { some_operation }
Defined Under Namespace
Classes: SpinnerError
Instance Attribute Summary collapse
-
#active_spinners ⇒ Object
Expose for testability.
Instance Method Summary collapse
-
#active_count ⇒ Object
Get count of active spinners.
-
#any_active? ⇒ Boolean
Check if any spinners are active.
-
#initialize ⇒ SpinnerHelper
constructor
A new instance of SpinnerHelper.
-
#stop_all ⇒ Object
Force stop all spinners (emergency cleanup).
-
#update_spinner_message(spinner, new_message) ⇒ Object
Update spinner message during operation.
- #with_analyzing_spinner(message, &block) ⇒ Object
- #with_building_spinner(message, &block) ⇒ Object
-
#with_loading_spinner(message, &block) ⇒ Object
Convenience methods for common patterns.
-
#with_long_operation_spinner(message, &block) ⇒ Object
For operations that might take a while.
- #with_processing_spinner(message, &block) ⇒ Object
-
#with_quick_spinner(message, &block) ⇒ Object
For quick operations.
- #with_saving_spinner(message, &block) ⇒ Object
-
#with_spinner(message, format: :dots, success_message: nil, error_message: nil, &block) ⇒ Object
Main method: automatically manages spinner around a block.
Constructor Details
#initialize ⇒ SpinnerHelper
Returns a new instance of SpinnerHelper.
17 18 19 20 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 17 def initialize @pastel = Pastel.new @active_spinners = [] end |
Instance Attribute Details
#active_spinners ⇒ Object
Expose for testability
15 16 17 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 15 def active_spinners @active_spinners end |
Instance Method Details
#active_count ⇒ Object
Get count of active spinners
83 84 85 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 83 def active_count @active_spinners.count(&:spinning?) end |
#any_active? ⇒ Boolean
Check if any spinners are active
78 79 80 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 78 def any_active? @active_spinners.any?(&:spinning?) end |
#stop_all ⇒ Object
Force stop all spinners (emergency cleanup)
88 89 90 91 92 93 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 88 def stop_all @active_spinners.each do |spinner| spinner.stop if spinner.spinning? end @active_spinners.clear end |
#update_spinner_message(spinner, new_message) ⇒ Object
Update spinner message during operation
73 74 75 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 73 def (spinner, ) spinner.update_title() end |
#with_analyzing_spinner(message, &block) ⇒ Object
54 55 56 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 54 def with_analyzing_spinner(, &block) with_spinner("🔍 #{}", format: :dots, &block) end |
#with_building_spinner(message, &block) ⇒ Object
58 59 60 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 58 def with_building_spinner(, &block) with_spinner("🏗️ #{}", format: :dots, &block) end |
#with_loading_spinner(message, &block) ⇒ Object
Convenience methods for common patterns
42 43 44 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 42 def with_loading_spinner(, &block) with_spinner("⏳ #{}", format: :dots, &block) end |
#with_long_operation_spinner(message, &block) ⇒ Object
For operations that might take a while
63 64 65 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 63 def with_long_operation_spinner(, &block) with_spinner("⏳ #{}", format: :pulse, &block) end |
#with_processing_spinner(message, &block) ⇒ Object
46 47 48 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 46 def with_processing_spinner(, &block) with_spinner("🔄 #{}", format: :pulse, &block) end |
#with_quick_spinner(message, &block) ⇒ Object
For quick operations
68 69 70 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 68 def with_quick_spinner(, &block) with_spinner("⚡ #{}", format: :dots, &block) end |
#with_saving_spinner(message, &block) ⇒ Object
50 51 52 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 50 def with_saving_spinner(, &block) with_spinner("💾 #{}", format: :dots, &block) end |
#with_spinner(message, format: :dots, success_message: nil, error_message: nil, &block) ⇒ Object
Main method: automatically manages spinner around a block
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 23 def with_spinner(, format: :dots, success_message: nil, error_message: nil, &block) raise ArgumentError, "Block required for with_spinner" unless block spinner = create_spinner(, format) start_spinner(spinner) begin result = yield(spinner) success_spinner(spinner, || ) result rescue => e error_spinner(spinner, || "Failed: #{e.}") raise e ensure cleanup_spinner(spinner) end end |