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 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.
14 15 16 17 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 14 def initialize @pastel = Pastel.new @active_spinners = [] end |
Instance Method Details
#active_count ⇒ Object
Get count of active spinners
80 81 82 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 80 def active_count @active_spinners.count(&:spinning?) end |
#any_active? ⇒ Boolean
Check if any spinners are active
75 76 77 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 75 def any_active? @active_spinners.any?(&:spinning?) end |
#stop_all ⇒ Object
Force stop all spinners (emergency cleanup)
85 86 87 88 89 90 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 85 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
70 71 72 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 70 def (spinner, ) spinner.update_title() end |
#with_analyzing_spinner(message, &block) ⇒ Object
51 52 53 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 51 def with_analyzing_spinner(, &block) with_spinner("🔍 #{}", format: :dots, &block) end |
#with_building_spinner(message, &block) ⇒ Object
55 56 57 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 55 def with_building_spinner(, &block) with_spinner("🏗️ #{}", format: :dots, &block) end |
#with_loading_spinner(message, &block) ⇒ Object
Convenience methods for common patterns
39 40 41 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 39 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
60 61 62 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 60 def with_long_operation_spinner(, &block) with_spinner("⏳ #{}", format: :pulse, &block) end |
#with_processing_spinner(message, &block) ⇒ Object
43 44 45 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 43 def with_processing_spinner(, &block) with_spinner("🔄 #{}", format: :pulse, &block) end |
#with_quick_spinner(message, &block) ⇒ Object
For quick operations
65 66 67 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 65 def with_quick_spinner(, &block) with_spinner("⚡ #{}", format: :dots, &block) end |
#with_saving_spinner(message, &block) ⇒ Object
47 48 49 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 47 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/aidp/harness/ui/spinner_helper.rb', line 20 def with_spinner(, format: :dots, success_message: nil, error_message: nil, &block) raise ArgumentError, "Block required for with_spinner" unless block_given? 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 |