mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
parent
4a9deb350d
commit
2fd5bbe1e7
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user