Module: Terrestrial::Cli::TerminalUI
- Defined in:
- lib/terrestrial/cli/terminal_ui.rb
Class Method Summary collapse
Class Method Details
.show_spinner(fps = 10) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/terrestrial/cli/terminal_ui.rb', line 5 def self.show_spinner(fps = 10) chars = %w[| / - \\] delay = 1.0/fps iter = 0 spinner = Thread.new do while iter do # Keep spinning until told otherwise print chars[(iter+=1) % chars.length] sleep delay print "\b" print " " print "\b" end end yield.tap do # After yielding to the block, save the return value iter = false # Tell the thread to exit, cleaning up after itself… spinner.join # …and wait for it to do so. end # Use the block's return value as the method's end |