class Schlib::Spinner

Public Class Methods

wait_for() { || ... } click to toggle source
# File lib/schlib/spinner.rb, line 5
def self.wait_for
  thread = create_spinner_thread
  value = yield
  thread.kill
  thread.join
  value
end

Private Class Methods

create_spinner_thread() click to toggle source
# File lib/schlib/spinner.rb, line 15
def self.create_spinner_thread
  Thread.new do
    begin
      i = 0
      frames = %w[▁ ▃ ▅ ▆ ▇ █ ▇ ▆ ▅ ▃]
      loop do
        frame = frames[i % frames.size]
        print "\rLoading #{frame} ... "
        sleep 0.1
        i += 1
      end
    ensure
      print "\rLoading ▇ ... done\n\n"
    end
  end
end