diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b14475..e358b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Master + +- Pull request [#137](https://github.com/guard/guard/pull/137): Fix interacting with tools like ruby-debug. ([@hron][] & [@netzpirat][]) + ## 0.7.0 - September 14, 2011 ## 0.7.0.rc1 - September 5, 2011 @@ -250,6 +254,7 @@ [@fnichol]: https://github.com/fnichol [@Gazer]: https://github.com/Gazer [@gix]: https://github.com/gix +[@hron]: https://github.com/hron [@hashrocketeer]: https://github.com/hashrocketeer [@ianwhite]: https://github.com/ianwhite [@indirect]: https://github.com/indirect diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 1ef94ca..c6c56b2 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -4,6 +4,7 @@ module Guard # specific action upon them unless its locked. # # Currently the following actions are implemented: + # # - stop, quit, exit, s, q, e => Exit Guard # - reload, r, z => Reload Guard # - pause, p => Pause Guard @@ -11,6 +12,9 @@ module Guard # class Interactor + class LockException < Exception; end + class UnlockException < Exception; end + attr_reader :locked # Initialize the interactor in unlocked state. @@ -19,25 +23,31 @@ module Guard @locked = false end - # Start the interactor in a own thread. + # Start the interactor in its own thread. # def start return if ENV["GUARD_ENV"] == 'test' - Thread.new do + @thread = Thread.new do loop do - if (entry = $stdin.gets) && !@locked - entry.gsub! /\n/, '' - case entry - when 'stop', 'quit', 'exit', 's', 'q', 'e' - ::Guard.stop - when 'reload', 'r', 'z' - ::Guard.reload - when 'pause', 'p' - ::Guard.pause - else - ::Guard.run_all + begin + if !@locked && (entry = $stdin.gets) + entry.gsub! /\n/, '' + case entry + when 'stop', 'quit', 'exit', 's', 'q', 'e' + ::Guard.stop + when 'reload', 'r', 'z' + ::Guard.reload + when 'pause', 'p' + ::Guard.pause + else + ::Guard.run_all + end end + rescue LockException + lock + rescue UnlockException + unlock end end end @@ -46,13 +56,21 @@ module Guard # Lock the interactor. # def lock - @locked = true + if !@thread || @thread == Thread.current + @locked = true + else + @thread.raise(LockException) + end end # Unlock the interactor. # def unlock - @locked = false + if !@thread || @thread == Thread.current + @locked = false + else + @thread.raise(UnlockException) + end end end diff --git a/man/guard b/man/guard index b1a93f0..3260c45 100644 --- a/man/guard +++ b/man/guard @@ -17,6 +17,47 @@ . .nf +NAME +NAME +. +.fi +. +.IP "" 0 +. +.P +. +.P +. +.IP "" 4 +. +.nf + +
  • guard
  • +
  • +
  • guard
  • +. +.fi +. +.IP "" 0 +. +.P +. +.P +. +.P +\fBguard\fR +. +.P +\fI!DOCTYPE html\fR +. +.P +. +.P +. +.IP "" 4 +. +.nf + NAME . .fi @@ -66,4 +107,22 @@ .P . .P +. +.P +. +.IP "" 4 +. +.nf + +
  • +
  • September 2011
  • +
  • guard
  • +. +.fi +. +.IP "" 0 +. +.P +. +.P diff --git a/man/guard.html b/man/guard.html index ecd1ac7..604ffa2 100644 --- a/man/guard.html +++ b/man/guard.html @@ -55,6 +55,7 @@
      @@ -70,10 +71,10 @@

      !DOCTYPE html - + guard - +

      + + + + + + + + + +

      +

      + + + + +