aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-12-20 11:44:47 +1300
committerAldo Cortesi <aldo@corte.si>2017-12-20 11:44:47 +1300
commit2fd5bbe1e7db79ba2678cbb7875825d056f55762 (patch)
tree75d21faa4beba32d62eec4679e3aaa959c481729
parent4a9deb350df3d9f2f17533cfe10baad51b7b5426 (diff)
downloadmitmproxy-2fd5bbe1e7db79ba2678cbb7875825d056f55762.tar.gz
mitmproxy-2fd5bbe1e7db79ba2678cbb7875825d056f55762.tar.bz2
mitmproxy-2fd5bbe1e7db79ba2678cbb7875825d056f55762.zip
console: ignore non-nav keys in chooser
Awkward, but works Fixes #2417
-rw-r--r--mitmproxy/tools/console/keymap.py17
-rw-r--r--mitmproxy/tools/console/overlay.py13
2 files changed, 28 insertions, 2 deletions
diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py
index b268906c..fbb569a4 100644
--- a/mitmproxy/tools/console/keymap.py
+++ b/mitmproxy/tools/console/keymap.py
@@ -17,6 +17,13 @@ Contexts = {
}
+navkeys = [
+ "m_start", "m_end", "m_next", "m_select",
+ "up", "down", "page_up", "page_down",
+ "left", "right"
+]
+
+
class Binding:
def __init__(self, key, command, contexts, help):
self.key, self.command, self.contexts = key, command, sorted(contexts)
@@ -122,3 +129,13 @@ class Keymap:
if b:
return self.executor(b.command)
return key
+
+ def handle_only(self, context: str, key: str) -> typing.Optional[str]:
+ """
+ Like handle, but ignores global bindings. Returns the key if it has
+ not been handled, or None.
+ """
+ b = self.get(context, key)
+ if b:
+ return self.executor(b.command)
+ return key
diff --git a/mitmproxy/tools/console/overlay.py b/mitmproxy/tools/console/overlay.py
index f97f23f9..55acbfdd 100644
--- a/mitmproxy/tools/console/overlay.py
+++ b/mitmproxy/tools/console/overlay.py
@@ -5,6 +5,7 @@ import urwid
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import grideditor
from mitmproxy.tools.console import layoutwidget
+from mitmproxy.tools.console import keymap
class SimpleOverlay(urwid.Overlay, layoutwidget.LayoutWidget):
@@ -114,13 +115,21 @@ class Chooser(urwid.WidgetWrap, layoutwidget.LayoutWidget):
return True
def keypress(self, size, key):
- key = self.master.keymap.handle("chooser", key)
+ key = self.master.keymap.handle_only("chooser", key)
if key == "m_select":
self.callback(self.choices[self.walker.index])
signals.pop_view_state.send(self)
+ return
elif key == "esc":
signals.pop_view_state.send(self)
- return super().keypress(size, key)
+ return
+
+ binding = self.master.keymap.get("global", key)
+ # This is extremely awkward. We need a better way to match nav keys only.
+ if binding and binding.command.startswith("console.nav"):
+ self.master.keymap.handle("global", key)
+ elif key in keymap.navkeys:
+ return super().keypress(size, key)
class OptionsOverlay(urwid.WidgetWrap, layoutwidget.LayoutWidget):