Class: Anima::Spinner
- Inherits:
-
Object
- Object
- Anima::Spinner
- Defined in:
- lib/anima/spinner.rb
Overview
Braille spinner for long-running CLI operations. Animates in a background thread while a block executes in the calling thread, then shows a success/failure indicator.
Constant Summary collapse
- FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
- FRAME_DELAY =
0.08- SUCCESS_ICON =
"\u2713"- FAILURE_ICON =
"\u2717"- JOIN_TIMEOUT =
2
Class Method Summary collapse
-
.run(message, output: $stdout) { ... } ⇒ Object
Run a block with an animated spinner beside a status message.
Instance Method Summary collapse
-
#initialize(message, output: $stdout) ⇒ Spinner
constructor
A new instance of Spinner.
-
#run { ... } ⇒ Object
The block’s return value.
Constructor Details
#initialize(message, output: $stdout) ⇒ Spinner
Returns a new instance of Spinner.
29 30 31 32 33 34 |
# File 'lib/anima/spinner.rb', line 29 def initialize(, output: $stdout) @message = @output = output @mutex = Mutex.new @running = false end |
Class Method Details
.run(message, output: $stdout) { ... } ⇒ Object
Run a block with an animated spinner beside a status message.
23 24 25 |
# File 'lib/anima/spinner.rb', line 23 def self.run(, output: $stdout, &block) new(, output: output).run(&block) end |
Instance Method Details
#run { ... } ⇒ Object
Returns the block’s return value.
38 39 40 41 42 43 44 45 46 |
# File 'lib/anima/spinner.rb', line 38 def run thread = start_animation result = yield stop_animation(thread, success: !!result) result rescue stop_animation(thread, success: false) raise end |