sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit e8256110454394f316cd2a8135a628e458f4ea55
parent 9076db779afc223da0e72dbab4e6cebb6dcbe9bf
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sun, 24 Jan 2010 19:09:32 -0800

add keymap rebinding support

Keymap#delete removes an existing keybinding and Keymap#add! deletes existing
bindings to the given keys before adding new ones. Keymap#add_multi now allows
adding new bindings to an existing submap.

Diffstat:
M lib/sup/keymap.rb | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/lib/sup/keymap.rb b/lib/sup/keymap.rb
@@ -60,10 +60,31 @@ class Keymap
     end
   end
 
+  def delete k
+    kc = Keymap.keysym_to_keycode(k)
+    return unless @map.member? kc
+    entry = @map.delete kc
+    keys = entry[2]
+    keys.delete k
+    @order.delete entry if keys.empty?
+  end
+
+  def add! action, help, *keys
+    keys.each { |k| delete k }
+    add action, help, *keys
+  end
+
   def add_multi prompt, key
-    submap = Keymap.new
-    add submap, prompt, key
-    yield submap
+    kc = Keymap.keysym_to_keycode(key)
+    if @map.member? kc
+      action = @map[kc].first
+      raise "existing action is not a keymap" unless action.is_a?(Keymap)
+      yield action
+    else
+      submap = Keymap.new
+      add submap, prompt, key
+      yield submap
+    end
   end
 
   def action_for kc