mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-01-12 17:32:27 +08:00
command: partials
Support partial commands in console.command, use it to keybind "i" for intercept, which prompts the user with ":set intercept=".
This commit is contained in:
@@ -56,7 +56,7 @@ def safecall():
|
||||
try:
|
||||
with contextlib.redirect_stdout(stdout_replacement):
|
||||
yield
|
||||
except exceptions.AddonHalt:
|
||||
except (exceptions.AddonHalt, exceptions.OptionsError):
|
||||
raise
|
||||
except Exception as e:
|
||||
etype, value, tb = sys.exc_info()
|
||||
|
||||
@@ -83,9 +83,9 @@ class ConsoleCommands:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
|
||||
def command(self) -> None:
|
||||
def command(self, partial: str) -> None:
|
||||
"""Prompt for a command."""
|
||||
signals.status_prompt_command.send()
|
||||
signals.status_prompt_command.send(partial=partial)
|
||||
|
||||
def view_commands(self) -> None:
|
||||
"""View the commands list."""
|
||||
@@ -120,12 +120,13 @@ class ConsoleCommands:
|
||||
|
||||
|
||||
def default_keymap(km):
|
||||
km.add(":", "console.command")
|
||||
km.add(":", "console.command ''")
|
||||
km.add("?", "console.view.help")
|
||||
km.add("C", "console.view.commands")
|
||||
km.add("O", "console.view.options")
|
||||
km.add("Q", "console.exit")
|
||||
km.add("q", "console.view.pop")
|
||||
km.add("i", "console.command 'set intercept='")
|
||||
|
||||
|
||||
class ConsoleMaster(master.Master):
|
||||
|
||||
@@ -82,15 +82,4 @@ class Window(urwid.Frame):
|
||||
|
||||
def keypress(self, size, k):
|
||||
k = super().keypress(size, k)
|
||||
k = self.master.keymap.handle("", k)
|
||||
if not k:
|
||||
return
|
||||
elif k == "i":
|
||||
signals.status_prompt.send(
|
||||
self,
|
||||
prompt = "Intercept filter",
|
||||
text = self.master.options.intercept,
|
||||
callback = self.master.options.setter("intercept")
|
||||
)
|
||||
else:
|
||||
return k
|
||||
return self.master.keymap.handle("", k)
|
||||
|
||||
@@ -7,6 +7,8 @@ import pytest
|
||||
def test_set():
|
||||
sa = core.Core()
|
||||
with taddons.context() as tctx:
|
||||
tctx.master.addons.add(sa)
|
||||
|
||||
assert not tctx.master.options.anticomp
|
||||
tctx.command(sa.set, "anticomp")
|
||||
assert tctx.master.options.anticomp
|
||||
|
||||
Reference in New Issue
Block a user