mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
console: teach keymap to understand "space"
Urwid uses " ", which is not a great user experience.
This commit is contained in:
parent
08972c3f5b
commit
4a7cafee9e
@ -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",
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user