Module: Philiprehberger::CliKit::Spinner
- Defined in:
- lib/philiprehberger/cli_kit/spinner.rb
Overview
Animated spinner for long-running CLI operations.
Constant Summary collapse
- FRAMES =
%w[| / - \\].freeze
Class Method Summary collapse
-
.spinner(message, output: $stderr) { ... } ⇒ Object
Display a spinner while executing a block.
Class Method Details
.spinner(message, output: $stderr) { ... } ⇒ Object
Display a spinner while executing a block.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/philiprehberger/cli_kit/spinner.rb', line 15 def self.spinner(, output: $stderr, &block) done = false result = nil thread = Thread.new do frame = 0 until done output.print "\r#{FRAMES[frame % FRAMES.length]} #{}" output.flush frame += 1 sleep 0.1 end output.print "\r\e[K" output.flush end begin result = block.call ensure done = true thread.join end result end |