1998-01-16 07:13:05 -05:00
|
|
|
#! /usr/local/bin/ruby
|
|
|
|
|
|
|
|
require "thread"
|
|
|
|
require "observer"
|
|
|
|
|
|
|
|
class Tick
|
|
|
|
include Observable
|
|
|
|
def initialize
|
|
|
|
Thread.start do
|
1999-01-19 23:59:39 -05:00
|
|
|
loop do
|
2013-07-20 09:41:02 -04:00
|
|
|
sleep 0.999
|
|
|
|
now = Time.now
|
|
|
|
changed
|
|
|
|
notify_observers(now.hour, now.min, now.sec)
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Clock
|
1999-01-19 23:59:39 -05:00
|
|
|
def initialize(tick)
|
|
|
|
@tick = tick
|
1998-01-16 07:13:05 -05:00
|
|
|
@tick.add_observer(self)
|
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
def update(h, m, s)
|
|
|
|
printf "\e[8D%02d:%02d:%02d", h, m, s
|
1998-01-16 07:13:05 -05:00
|
|
|
STDOUT.flush
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
clock = Clock.new(Tick.new)
|
1998-01-16 07:13:05 -05:00
|
|
|
sleep
|