diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-06-13 15:36:00 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-06-13 15:36:00 +1200 |
commit | 4a7cafee9efe1bff21d95eba0e5d42d610e70484 (patch) | |
tree | 6135458318199df08a10643e3cea199731eef8e9 | |
parent | 08972c3f5bb76b6ff60ea3124c85e3e3cd6f30f0 (diff) | |
download | mitmproxy-4a7cafee9efe1bff21d95eba0e5d42d610e70484.tar.gz mitmproxy-4a7cafee9efe1bff21d95eba0e5d42d610e70484.tar.bz2 mitmproxy-4a7cafee9efe1bff21d95eba0e5d42d610e70484.zip |
console: teach keymap to understand "space"
Urwid uses " ", which is not a great user experience.
-rw-r--r-- | mitmproxy/tools/console/defaultkeys.py | 4 | ||||
-rw-r--r-- | mitmproxy/tools/console/keymap.py | 18 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_keymap.py | 5 |
3 files changed, 19 insertions, 8 deletions
diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index cfefd533..799ffb4e 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -20,7 +20,7 @@ def map(km): km.add("h", "console.nav.left", ["global"], "Left") km.add("tab", "console.nav.next", ["global"], "Next") km.add("enter", "console.nav.select", ["global"], "Select") - km.add(" ", "console.nav.pagedown", ["global"], "Page down") + km.add("space", "console.nav.pagedown", ["global"], "Page down") km.add("ctrl f", "console.nav.pagedown", ["global"], "Page down") km.add("ctrl b", "console.nav.pageup", ["global"], "Page up") @@ -102,7 +102,7 @@ def map(km): "Toggle viewing full contents on this flow", ) km.add("w", "console.command save.file @focus ", ["flowview"], "Save flow to file") - km.add(" ", "view.focus.next", ["flowview"], "Go to next flow") + km.add("space", "view.focus.next", ["flowview"], "Go to next flow") km.add( "v", diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py index 4d8c3ec2..19994db7 100644 --- a/mitmproxy/tools/console/keymap.py +++ b/mitmproxy/tools/console/keymap.py @@ -1,5 +1,4 @@ import typing -import collections from mitmproxy.tools.console import commandeditor @@ -16,10 +15,17 @@ SupportedContexts = { } -Binding = collections.namedtuple( - "Binding", - ["key", "command", "contexts", "help"] -) +class Binding: + def __init__(self, key, command, contexts, help): + self.key, self.command, self.contexts = key, command, contexts + self.help = help + + def keyspec(self): + """ + Translate the key spec from a convenient user specification to one + Urwid understands. + """ + return self.key.replace("space", " ") class Keymap: @@ -46,7 +52,7 @@ class Keymap: def bind(self, binding): for c in binding.contexts: d = self.keys.setdefault(c, {}) - d[binding.key] = binding.command + d[binding.keyspec()] = binding.command def get(self, context: str, key: str) -> typing.Optional[str]: if context in self.keys: diff --git a/test/mitmproxy/tools/console/test_keymap.py b/test/mitmproxy/tools/console/test_keymap.py index bbca4ac9..fdb2b028 100644 --- a/test/mitmproxy/tools/console/test_keymap.py +++ b/test/mitmproxy/tools/console/test_keymap.py @@ -4,6 +4,11 @@ from unittest import mock import pytest +def test_binding(): + b = keymap.Binding("space", "cmd", ["options"], "") + assert b.keyspec() == " " + + def test_bind(): with taddons.context() as tctx: km = keymap.Keymap(tctx.master) |