aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2020-04-08 17:41:43 +0200
committerGitHub <noreply@github.com>2020-04-08 17:41:43 +0200
commit4d6886a0f4ebbf6bc66b74fa548ff724ba2ad660 (patch)
treeafe4b9edb31e5fc6752f9c855fe72b549e7f840f
parent3ebf112d6d7f7b3484d51e2ac51b593cd5b1a5bb (diff)
parent4d2cb321d6fbbb1813fd9ae4d38568be8d3d4cb4 (diff)
downloadmitmproxy-4d6886a0f4ebbf6bc66b74fa548ff724ba2ad660.tar.gz
mitmproxy-4d6886a0f4ebbf6bc66b74fa548ff724ba2ad660.tar.bz2
mitmproxy-4d6886a0f4ebbf6bc66b74fa548ff724ba2ad660.zip
Merge pull request #3912 from KevCui/master
#3911 Support keybinding for different contexts with different commands
-rw-r--r--mitmproxy/tools/console/keymap.py2
-rw-r--r--test/mitmproxy/tools/console/test_keymap.py22
2 files changed, 19 insertions, 5 deletions
diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py
index 01ec9a0a..a42225cf 100644
--- a/mitmproxy/tools/console/keymap.py
+++ b/mitmproxy/tools/console/keymap.py
@@ -202,7 +202,7 @@ class KeymapConfig:
user_ctxs = v.get("ctx", ["global"])
try:
km._check_contexts(user_ctxs)
- km.remove(v["key"], Contexts)
+ km.remove(v["key"], user_ctxs)
km.add(
key = v["key"],
command = v["cmd"],
diff --git a/test/mitmproxy/tools/console/test_keymap.py b/test/mitmproxy/tools/console/test_keymap.py
index 0d6f9e88..f2c97ded 100644
--- a/test/mitmproxy/tools/console/test_keymap.py
+++ b/test/mitmproxy/tools/console/test_keymap.py
@@ -117,6 +117,21 @@ def test_load_path(tmpdir):
kmc.load_path(km, dst)
assert(km.get("chooser", "key1"))
+ with open(dst, 'w') as f:
+ f.write(
+ """
+ - key: key2
+ ctx: [flowlist]
+ cmd: foo
+ - key: key2
+ ctx: [flowview]
+ cmd: bar
+ """
+ )
+ kmc.load_path(km, dst)
+ assert(km.get("flowlist", "key2"))
+ assert(km.get("flowview", "key2"))
+
km.add("key123", "str", ["flowlist", "flowview"])
with open(dst, 'w') as f:
f.write(
@@ -127,10 +142,9 @@ def test_load_path(tmpdir):
"""
)
kmc.load_path(km, dst)
- for b in km.bindings:
- if b.key == "key123":
- assert b.contexts == ["options"]
- break
+ assert(km.get("flowlist", "key123"))
+ assert(km.get("flowview", "key123"))
+ assert(km.get("options", "key123"))
def test_parse():