[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] [PATCHv3] idle and unidle updates



Now handled outside of the main thread to accommodate shelling out to
the editor.

[PATCH] flush index on idle
and
[PATCHv5] [issue14] poll updates accumulate while idle
will still work with this patch.
---
 bin/sup         |    4 ++++
 lib/sup.rb      |    2 ++
 lib/sup/idle.rb |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)
 create mode 100644 lib/sup/idle.rb

diff --git a/bin/sup b/bin/sup
index 8bf640b..a5d48f6 100755
--- a/bin/sup
+++ b/bin/sup
@@ -239,6 +239,7 @@ begin
 
   unless $opts[:no_threads]
     PollManager.start
+    IdleManager.start
     Index.start_lock_update_thread
   end
 
@@ -263,6 +264,8 @@ begin
       next
     end
 
+    IdleManager.ping
+
     if c == 410
       ## this is ncurses's way of telling us it's detected a refresh.
       ## since we have our own sigwinch handler, we don't do anything.
@@ -366,6 +369,7 @@ rescue Exception => e
 ensure
   unless $opts[:no_threads]
     PollManager.stop if PollManager.instantiated?
+    IdleManager.stop if IdleManager.instantiated?
     Index.stop_lock_update_thread
   end
 
diff --git a/lib/sup.rb b/lib/sup.rb
index e03a35d..2fbaa02 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -131,6 +131,7 @@ module Redwood
     Redwood::CryptoManager.init
     Redwood::UndoManager.init
     Redwood::SourceManager.init
+    Redwood::IdleManager.init
   end
 
   def finish
@@ -341,6 +342,7 @@ require "sup/modes/file-browser-mode"
 require "sup/modes/completion-mode"
 require "sup/modes/console-mode"
 require "sup/sent"
+require "sup/idle"
 
 $:.each do |base|
   d = File.join base, "sup/share/modes/"
diff --git a/lib/sup/idle.rb b/lib/sup/idle.rb
new file mode 100644
index 0000000..a3a272f
--- /dev/null
+++ b/lib/sup/idle.rb
@@ -0,0 +1,42 @@
+require 'thread'
+
+module Redwood
+
+class IdleManager
+  include Singleton
+
+  IDLE_THRESHOLD = 60
+
+  def initialize
+    @no_activity_since = Time.now
+    @idle = false
+    @thread = nil
+  end
+
+  def ping
+    if @idle
+      UpdateManager.relay self, :unidle, Time.at(@no_activity_since)
+      @idle = false
+    end
+    @no_activity_since = Time.now
+  end
+
+  def start
+    @thread = Redwood::reporting_thread("checking for idleness") do
+      while true
+        sleep 1
+        if !@idle and Time.now.to_i - @no_activity_since.to_i >= IDLE_THRESHOLD
+          UpdateManager.relay self, :idle, Time.at(@no_activity_since)
+          @idle = true
+        end
+      end
+    end
+  end
+
+  def stop
+    @thread.kill if @thread
+    @thread = nil
+  end
+end
+
+end
-- 
1.6.6
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel