Skip to content
Newer
Older
100644 29 lines (28 sloc) 704 Bytes
d685168 blank files, directory poller, and spinner
Mark Yoon authored
1 # 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
2 class Spinner
3 Baton = '\|/-'
4 def initialize
5 STDOUT.flush
6 @child = fork do
7 trap('SIGHUP') do
8 print " \b"
9 STDOUT.flush
10 exit!
11 end
12 rotation = 0
13 loop do
14 printf "%c\b", Baton[(rotation+=1)&3]
15 STDOUT.flush
16 sleep 0.1
17 end
18 end
19 end
20 def stop
21 Process.kill 'SIGHUP', @child
22 end
23 end
24 # animation = Spinner.new
25 # sleep 2
26 # puts "foo"
27 # sleep 2
28 # animation.stop
Something went wrong with that request. Please try again.