Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1e8d2ae47c
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (28 sloc) 0.704 kb
# http://books.google.com/books?id=bKCuEhzyUgMC&pg=PA279&lpg=PA279&dq=ruby+puts+spinner&source=bl&ots=vSYEoZOfJy&sig=FzD4Ss_GUlfCALIUIQd_GDVbxxI&hl=en&ei=ClJ8SuToGofYNvLwwO8C&sa=X&oi=book_result&ct=result&resnum=2#v=onepage&q=ruby%20puts%20spinner&f=false
class Spinner
Baton = '\|/-'
def initialize
STDOUT.flush
@child = fork do
trap('SIGHUP') do
print " \b"
STDOUT.flush
exit!
end
rotation = 0
loop do
printf "%c\b", Baton[(rotation+=1)&3]
STDOUT.flush
sleep 0.1
end
end
end
def stop
Process.kill 'SIGHUP', @child
end
end
# animation = Spinner.new
# sleep 2
# puts "foo"
# sleep 2
# animation.stop
Jump to Line
Something went wrong with that request. Please try again.