Sha256: 9de6ac3c779c558a7084adbc5e97a2f2261dd373b8f7b95224661274f8ccfdfa
Contents?: true
Size: 809 Bytes
Versions: 36
Compression:
Stored size: 809 Bytes
Contents
module Locomotive::Wagon module SpinnerConcern # http://stackoverflow.com/questions/10262235/printing-an-ascii-spinning-cursor-in-the-console def show_wait_spinner(sentence = nil, fps = 10) chars = %w[| / - \\] delay = 1.0/fps iter = 0 spinner = Thread.new do print sentence if sentence while iter do # Keep spinning until told otherwise print chars[(iter += 1) % chars.length] sleep delay print "\b" end end yield.tap { # 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. } # Use the block's return value as the method's end end end
Version data entries
36 entries across 36 versions & 1 rubygems