Permalink
Browse files

add debugging output

  • Loading branch information...
1 parent d149a45 commit 3514b5d72cef8d784bf48bbf6a5019dbc8a0d9f3 @txus committed Aug 28, 2011
Showing with 37 additions and 3 deletions.
  1. +22 −3 lib/domodoro/client.rb
  2. +15 −0 lib/domodoro/server.rb
View
@@ -6,21 +6,29 @@ class << self
def start(host, port)
Config.load
+ puts "#{Time.now} - Domodoro listening on #{host}:#{port}"
+ puts "Visual notifications: #{Config.visual}"
+ puts "Sound notifications: #{Config.sound}\n"
EM.run do
EM.connect(host, port) do |c|
c.extend EM::P::LineText2
def c.receive_line(line)
case line
when /start/
- puts "#{Time.now} - Starting pomodoro!"
+ puts " - Starting pomodoro!"
Client.work
when /stop/
- puts "#{Time.now} - Pomdoro break!"
+ puts " - Pomodoro break!"
Client.break
end
end
end
+ EM.add_periodic_timer(1) do
+ EM.next_tick do
+ print_time
+ end
+ end
end
end
@@ -42,7 +50,7 @@ def break
Notify.notify "Domodoro", "Take a 5 min. break."
end
if Config.sound
- system("afplay #{path_to('stop.wav')} && afplay #{path_to('stop.mp3')}")
+ system("afplay #{path_to('stop.wav')}")
end
end
end
@@ -53,6 +61,17 @@ def path_to(asset)
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'assets', asset))
end
+ def print_time
+ hour = Time.now.hour.to_s.rjust(2, '0')
+ min = Time.now.min.to_s.rjust(2, '0')
+ secs = Time.now.sec.to_s.rjust(2, '0')
+ $stdout.print "\r"
+ $stdout.print " " * 20
+ $stdout.print "\r"
+ $stdout.print "#{hour}:#{min}:#{secs}"
+ $stdout.flush
+ end
+
end
end
end
View
@@ -13,10 +13,25 @@ def start(host='127.0.0.1', port='9111')
EM.add_periodic_timer(1) do
if Time.now.sec == 0
channel.broadcast(Time.now.hour, Time.now.min)
+ else
+ EM.next_tick do
+ print_time
+ end
end
end
end
end
+
+ def print_time
+ hour = Time.now.hour.to_s.rjust(2, '0')
+ min = Time.now.min.to_s.rjust(2, '0')
+ secs = Time.now.sec.to_s.rjust(2, '0')
+ $stdout.print "\r"
+ $stdout.print " " * 20
+ $stdout.print "\r"
+ $stdout.print "#{hour}:#{min}:#{secs}"
+ $stdout.flush
+ end
end
def initialize(channel)

0 comments on commit 3514b5d

Please sign in to comment.