Class: DeepTest::UI::Console::Spinner
- Inherits:
-
Object
- Object
- DeepTest::UI::Console::Spinner
- Defined in:
- lib/deep_test/ui/console.rb
Constant Summary collapse
- FRAMES =
['|', '/', '-', '\\']
- BACKSPACE =
"\x08"
- SECONDS_PER_FRAME =
0.5 / 4
Instance Method Summary collapse
-
#initialize(label) ⇒ Spinner
constructor
A new instance of Spinner.
- #show(string) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(label) ⇒ Spinner
Returns a new instance of Spinner.
44 45 46 |
# File 'lib/deep_test/ui/console.rb', line 44 def initialize(label) @label = label end |
Instance Method Details
#show(string) ⇒ Object
69 70 71 72 |
# File 'lib/deep_test/ui/console.rb', line 69 def show(string) $stdout.print string $stdout.flush end |
#start ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
62 63 64 65 66 67 |
# 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 |