aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-06-14 09:04:10 +1200
committerAldo Cortesi <aldo@corte.si>2017-06-14 09:04:10 +1200
commit254fe34d4ca972a3488433d0bb0a2a58492852c2 (patch)
tree33602b2455e650c426ea77a5f9a5bc5c8bd241a2
parent788f0f578438e0a5af44e34644e684f9c82e8774 (diff)
downloadmitmproxy-254fe34d4ca972a3488433d0bb0a2a58492852c2.tar.gz
mitmproxy-254fe34d4ca972a3488433d0bb0a2a58492852c2.tar.bz2
mitmproxy-254fe34d4ca972a3488433d0bb0a2a58492852c2.zip
console: add console.key.unbind.focus, bind "d" key in keymap editor
-rw-r--r--mitmproxy/tools/console/consoleaddons.py21
-rw-r--r--mitmproxy/tools/console/defaultkeys.py6
-rw-r--r--mitmproxy/tools/console/keybindings.py7
-rw-r--r--mitmproxy/tools/console/keymap.py14
4 files changed, 42 insertions, 6 deletions
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
index dc6e1a35..4a687ff5 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -438,7 +438,6 @@ class ConsoleAddon:
)
except ValueError as v:
raise exceptions.CommandError(v)
- signals.keybindings_change.send(self)
@command.command("console.key.unbind")
def key_unbind(self, contexts: typing.Sequence[str], key: str) -> None:
@@ -450,6 +449,26 @@ class ConsoleAddon:
except ValueError as v:
raise exceptions.CommandError(v)
+ def _keyfocus(self):
+ kwidget = self.master.window.current("keybindings")
+ if not kwidget:
+ raise exceptions.CommandError("Not viewing key bindings.")
+ f = kwidget.focus()
+ if not f:
+ raise exceptions.CommandError("No key binding focused")
+ return f
+
+ @command.command("console.key.unbind.focus")
+ def key_unbind_focus(self) -> None:
+ """
+ Un-bind the shortcut key currently focused in the key binding viewer.
+ """
+ b = self._keyfocus()
+ try:
+ self.master.keymap.remove(b.key, b.contexts)
+ except ValueError as v:
+ raise exceptions.CommandError(v)
+
def running(self):
self.started = True
diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py
index 2d58218b..7edf0fd8 100644
--- a/mitmproxy/tools/console/defaultkeys.py
+++ b/mitmproxy/tools/console/defaultkeys.py
@@ -158,3 +158,9 @@ def map(km):
["keybindings"],
"Add a key binding"
)
+ km.add(
+ "d",
+ "console.key.unbind.focus",
+ ["keybindings"],
+ "Unbind the currently focused key binding"
+ )
diff --git a/mitmproxy/tools/console/keybindings.py b/mitmproxy/tools/console/keybindings.py
index c656c437..cbde030a 100644
--- a/mitmproxy/tools/console/keybindings.py
+++ b/mitmproxy/tools/console/keybindings.py
@@ -49,6 +49,7 @@ class KeyListWalker(urwid.ListWalker):
def sig_modified(self, sender):
self.bindings = list(self.master.keymap.list("all"))
self._modified()
+ self.set_focus(min(self.index, len(self.bindings) - 1))
def get_edit_text(self):
return self.focus_obj.get_edit_text()
@@ -134,6 +135,12 @@ class KeyBindings(urwid.Pile, layoutwidget.LayoutWidget):
)
self.master = master
+ def focus(self):
+ if self.focus_position != 0:
+ return None
+ f = self.widget_list[0]
+ return f.walker.get_focus()[0].binding
+
def keypress(self, size, key):
if key == "m_next":
self.focus_position = (
diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py
index 5cb3c579..354b3aac 100644
--- a/mitmproxy/tools/console/keymap.py
+++ b/mitmproxy/tools/console/keymap.py
@@ -1,5 +1,6 @@
import typing
from mitmproxy.tools.console import commandeditor
+from mitmproxy.tools.console import signals
Contexts = {
@@ -63,11 +64,12 @@ class Keymap:
if help:
b.help = help
self.bind(b)
- return
-
- b = Binding(key=key, command=command, contexts=contexts, help=help)
- self.bindings.append(b)
- self.bind(b)
+ break
+ else:
+ b = Binding(key=key, command=command, contexts=contexts, help=help)
+ self.bindings.append(b)
+ self.bind(b)
+ signals.keybindings_change.send(self)
def remove(self, key: str, contexts: typing.Sequence[str]) -> None:
"""
@@ -80,7 +82,9 @@ class Keymap:
self.unbind(b)
b.contexts = [x for x in b.contexts if x != c]
if b.contexts:
+ self.bindings.append(b)
self.bind(b)
+ signals.keybindings_change.send(self)
def bind(self, binding: Binding) -> None:
for c in binding.contexts: