Class: Rubikon::Throbber

Inherits:
Thread
  • Object
show all
Defined in:
lib/rubikon/throbber.rb

Overview

A class for displaying and managing throbbers

See Also:

Author:

  • Sebastian Staudt

Since:

  • 0.2.0

Constant Summary collapse

SPINNER =

Since:

  • 0.2.0

'-\|/'

Instance Method Summary collapse

Constructor Details

#initialize(ostream, thread) ⇒ Throbber

Creates and runs a Throbber that outputs to the given IO stream while the given thread is alive

Parameters:

  • ostream (IO)

    the IO stream the throbber should be written to

  • thread (Thread)

    The thread that should be watched

See Also:

  • Application::InstanceMethods#throbber

Since:

  • 0.2.0



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