sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 0e1a7157417f7ae60544cb6453e384919b1de27c
parent b9eb905066ec0091d818039d0c142005aa19cccd
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sun, 17 May 2009 13:18:25 -0700

make UndoManager#register take a block

Also clean up logging messages, argument handling, etc.

Diffstat:
M lib/sup/undo.rb | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/lib/sup/undo.rb b/lib/sup/undo.rb
@@ -15,23 +15,20 @@ class UndoManager
     self.class.i_am_the_instance self
   end
 
-  def register desc, actions
-    actions = [actions] unless actions.is_a?Array
-    raise StandardError, "when would I need to undo 'nothing?'" unless actions.length > 0
-    Redwood::log "registering #{actions.length} actions: #{desc}"
-    @@actionlist.push({:desc => desc, :actions => actions})
+  def register desc, *actions, &b
+    actions = [*actions.flatten]
+    actions << b if b
+    raise ArgumentError, "need at least one action" unless actions.length > 0
+    @@actionlist.push :desc => desc, :actions => actions
   end
 
   def undo
-    unless @@actionlist.length == 0 then
+    unless @@actionlist.empty?
       actionset = @@actionlist.pop
-      Redwood::log "undoing #{actionset[:desc]}..."
-      actionset[:actions].each{|action|
-        action.call
-      }
+      actionset[:actions].each { |action| action.call }
       BufferManager.flash "undid #{actionset[:desc]}"
     else
-      BufferManager.flash "nothing more to undo"
+      BufferManager.flash "nothing more to undo!"
     end
   end