Class: Rubikon::Throbber
Overview
A class for displaying and managing throbbers
Constant Summary collapse
- SPINNER =
'-\|/'
Instance Method Summary collapse
-
#initialize(ostream, thread) ⇒ Throbber
constructor
Creates and runs a Throbber that outputs to the given IO stream while the given thread is alive.
Constructor Details
#initialize(ostream, thread) ⇒ Throbber
Creates and runs a Throbber that outputs to the given IO stream while the given thread is alive
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rubikon/throbber.rb', line 23 def initialize(ostream, thread) proc = Proc.new do |os, thr| step = 0 os.putc 32 while thr.alive? os << "\b#{SPINNER[step].chr}" os.flush step = (step + 1) % 4 sleep 0.25 end os.putc 8 end super { proc.call(ostream, thread) } end |