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