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

[sup-talk] [PATCH 1/4] Add method to shell out asynchronously



Add shell_out_async method to fork and detach the editor, and register
the monitoring thread in PollManager.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 lib/sup/buffer.rb |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 5772bb0..25a2025 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -768,6 +768,26 @@ EOS
     @shelled = false
   end
 
+  def shell_out_async editor, file
+    @shelled = true
+    command = "#{editor} #{file.path}"
+    mtime = File.mtime file.path
+
+    Ncurses.sync do
+      pid = Process.fork
+      if pid.nil?
+        exec(command)
+      else
+        pthread = Process.detach(pid)
+        PollManager.editor_loop_init pthread, file, mtime
+      end
+      Ncurses.stdscr.keypad 1
+      Ncurses.refresh
+      Ncurses.curs_set 0
+    end
+    @shelled = false
+  end
+
 private
 
   def default_status_bar buf
-- 
1.7.0.4
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk