sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit d3fea1afa750f36dbf671027134a991a006669d7
parent e96e61bccfb473b81d45393def67953b1bddc868
Author: Hamish Downer <dmishd@gmail.com>
Date:   Tue, 15 Feb 2011 21:16:35 +0000

more baby steps towards async mode

Diffstat:
M lib/sup/modes/edit-message-async-mode.rb | 56 +++++++++++++++++++++++++++++++++++++++-----------------
M lib/sup/modes/edit-message-mode.rb | 14 ++------------
2 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/lib/sup/modes/edit-message-async-mode.rb b/lib/sup/modes/edit-message-async-mode.rb
@@ -1,41 +1,63 @@
 # edit-message-async-mode
 #
+module Redwood
 
-class EditMessageAsyncMode < Mode
+class EditMessageAsyncMode < LineCursorMode
   # TODO:
   #
   # * set up keymap - just X to say you're done
+  attr_reader :status
+  bool_reader :edited
 
-  # * generate buffer text
-  # * override mode bits - killable etc.
+  register_keymap do |k|
+    k.add :edit_finished, "Finished editing message", 'E'
+  end
 
   # * initialize function - need
   # ** file path
   # ** info to restart edit mode it started in
-  def initialize
+  def initialize file_path, title, finish_condition
+    @file_path = file_path
+    @finish_condition = finish_condition
+    @title = title
+    
+    @text = []
+    super {}
+  end
+
+  def lines; @text.length end
+
+  def [] i
+    @text[i]
   end
 
+protected
+  # * override mode bits - killable etc.
+
   def edit_finished
-    #
     # We need a edit_message_async_resume method, but maybe that 
     # should be in another mode?? The below code should run in it
  
     # first make sure any external editor has exited
-    File.open(@file.path, 'r') { |f|
-      while !f.flock(File::LOCK_EX|File::LOCK_NB)
+    File.open(@file_path, 'r') { |f|
+      if !f.flock(File::LOCK_EX|File::LOCK_NB)
         # ask user to check that any editor of that file has exited
-        # press enter when ready to continue
+        # press E again when they are ready
+        return false
       end
     }
-    @edited = true if File.mtime(@file.path) > @mtime
-
-    return @edited unless @edited
-
-    header, @body = parse_file @file.path
-    @header = header - NON_EDITABLE_HEADERS
-    handle_new_text @header, @body
-    update
+    # now we resume no matter what
+    # first we send the signal to the buffer that killed us
+    # then we kill ourselves
+    BufferManager.kill_buffer buffer
+  end
 
-    @edited
+  # this will be called if <Enter> is pressed
+  # nothing useful to do, so make it a no-op until we think of something better
+  # to do ...
+  def select
+    nil
   end
 end
+
+end
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -198,21 +198,11 @@ EOS
     # terminal or app, and continue to use sup in the meantime.
     # When you are done, navigate back to this buffer and press
     # X to resume
-    mode = EditMessageAsync.new m, type_arg
+    mode = EditMessageAsync.new @file.path, condition_var
     BufferManager.spawn "Waiting for message \"#{m.subj}\" to be finished", mode
 
-    # now do we kill our own mode? how?
+    # hide ourselves, and wait for signal to resume from async mode ...
 
-    # We need a edit_message_async_resume method, but maybe that 
-    # should be in another mode?? The below code should run in it
- 
-    # first make sure any external editor has exited
-    File.open(@file.path, 'r') { |f|
-      while !f.flock(File::LOCK_EX|File::LOCK_NB)
-        # ask user to check that any editor of that file has exited
-        # press enter when ready to continue
-      end
-    }
     @edited = true if File.mtime(@file.path) > @mtime
 
     return @edited unless @edited