Permalink
Browse files

better keypress thread management; add 'Change detected' message with…

… file counts
  • Loading branch information...
1 parent f8d96db commit 17b45aee2dafaa11d7396c0a41458735b934100a @alexch committed Jul 2, 2012
Showing with 22 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +20 −7 lib/rerun/runner.rb
  3. +1 −1 rerun.gemspec
View
@@ -2,3 +2,4 @@
pkg
Gemfile.lock
doc
+tmp
View
@@ -18,9 +18,7 @@ def initialize(run_command, options = {})
end
def start_keypress_thread
- from = caller.first
@keypress_thread = Thread.new do
- # puts "starting keypress thread #{Thread.current.object_id} from #{from}"
while true
if c = key_pressed
case c.downcase
@@ -30,10 +28,17 @@ def start_keypress_thread
when 'r'
say "Restarting"
restart
- break # the break will stop this thread
when 'x', 'q'
die
break # the break will stop this thread, in case the 'die' doesn't
+ when 't'
+ puts
+ puts "#{Thread.list.size} threads:"
+ Thread.list.each do |t|
+ puts "#{t.object_id}\tstatus: #{t.status}"
+ puts "\t" + t.backtrace[0..5].join("\n\t")
+ puts
+ end
else
puts "\n#{c.inspect} pressed inside rerun"
puts [["c", "clear screen"],
@@ -45,12 +50,11 @@ def start_keypress_thread
end
sleep 1 # todo: use select instead of polling somehow?
end
- # puts "keypress thread #{Thread.current.object_id} ending"
end
@keypress_thread.run
end
- def kill_keypress_thread
+ def stop_keypress_thread
@keypress_thread.kill if @keypress_thread
@keypress_thread = nil
end
@@ -101,7 +105,7 @@ def start
end
clear_screen if clear?
- start_keypress_thread
+ start_keypress_thread unless @keypress_thread
@pid = Kernel.fork do
begin
@@ -144,7 +148,15 @@ def start
unless @watcher
- watcher = Watcher.new(:directory => dir, :pattern => pattern) do
+ watcher = Watcher.new(:directory => dir, :pattern => pattern) do |changes|
+
+ message = [:modified, :added, :removed].map do |change|
+ count = changes[change].size
+ if count and count > 0
+ "#{count} #{change}"
+ end
+ end.compact.join(", ")
+ say "Change detected: #{message}"
restart unless @restarting
end
watcher.start
@@ -154,6 +166,7 @@ def start
end
def die
+ #stop_keypress_thread # don't do this since we're probably *in* the keypress thread
stop # stop the child process if it exists
exit 0 # todo: status code param
end
View
@@ -3,7 +3,7 @@ $spec = Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.name = 'rerun'
- s.version = '0.7.0.pre4'
+ s.version = '0.7.0.pre5'
s.description = "Restarts your app when a file changes"
s.summary = "Launches an app, and restarts it whenever the filesystem changes."

0 comments on commit 17b45ae

Please sign in to comment.