Class: Kennel::Progress
- Inherits:
-
Object
- Object
- Kennel::Progress
- Defined in:
- lib/kennel/progress.rb
Class Method Summary collapse
-
.progress(name) ⇒ Object
print what we are doing and a spinner until it is done …
Class Method Details
.progress(name) ⇒ Object
print what we are doing and a spinner until it is done … then show how long it took
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kennel/progress.rb', line 7 def self.progress(name) Kennel.err.print "#{name} ... " animation = "-\\|/" count = 0 stop = false result = nil spinner = Thread.new do loop do break if stop Kennel.err.print animation[count % animation.size] sleep 0.2 Kennel.err.print "\b" count += 1 end end time = Benchmark.realtime { result = yield } stop = true spinner.join Kennel.err.print "#{time.round(2)}s\n" result end |