]> git.cworth.org Git - sup/blobdiff - lib/sup/mode.rb
make >From thing work correctly
[sup] / lib / sup / mode.rb
index 91bdbe6c059d7791b28832d825fd269809caa600..7d437e2237c19eeb3c85fcd2700fe119230bde1e 100644 (file)
@@ -48,12 +48,9 @@ class Mode
   end
 
   def handle_input c
-    if(action = resolve_input c)
-      send action
-      true
-    else
-      false
-    end
+    action = resolve_input(c) or return false
+    send action
+    true
   end
 
   def help_text
@@ -75,6 +72,19 @@ EOS
       s
     end.compact.join "\n"
   end
+
+  ## helper function
+  def save_to_file fn
+    if File.exists? fn
+      return unless BufferManager.ask_yes_or_no "File exists. Overwrite?"
+    end
+    begin
+      File.open(fn, "w") { |f| yield f }
+      BufferManager.flash "Successfully wrote #{fn}."
+    rescue SystemCallError, IOError => e
+      BufferManager.flash "Error writing to file: #{e.message}"
+    end
+  end
 end
 
 end