class DeepTest::UI::Console::Spinner

Constants

BACKSPACE
FRAMES
SECONDS_PER_FRAME

Public Class Methods

new(label) click to toggle source
# File lib/deep_test/ui/console.rb, line 44
def initialize(label)
  @label = label
end

Public Instance Methods

show(string) click to toggle source
# File lib/deep_test/ui/console.rb, line 69
def show(string)
  $stdout.print string
  $stdout.flush
end
start() click to toggle source
# File lib/deep_test/ui/console.rb, line 48
def start
  @start_time = Time.now
  show "#{@label}: "
  @thread = Thread.new do
    index = 0
    loop do
      show FRAMES[index]
      sleep SECONDS_PER_FRAME
      show BACKSPACE
      index = (index + 1) % FRAMES.length
    end
  end 
end
stop() click to toggle source
# File lib/deep_test/ui/console.rb, line 62
def stop
  @stop_time = Time.now
  @thread.kill if @thread
  show BACKSPACE
  show("finished in %.2f seconds\n" % (@stop_time.to_f - @start_time.to_f))
end