diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index 2dc0e3442..d5b868d07 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -135,3 +135,5 @@ def map(km): "Read a Python-style escaped string from file" ) km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor") + + km.add("z", "console.eventlog.clear", ["eventlog"], "Clear") diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py index 1e56a05a7..5fdada9f7 100644 --- a/mitmproxy/tools/console/eventlog.py +++ b/mitmproxy/tools/console/eventlog.py @@ -18,16 +18,14 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget): self.master = master urwid.ListBox.__init__(self, self.walker) signals.sig_add_log.connect(self.sig_add_log) + signals.sig_clear_log.connect(self.sig_clear_log) def set_focus(self, index): if 0 <= index < len(self.walker): super().set_focus(index) def keypress(self, size, key): - if key == "z": - self.clear_events() - key = None - elif key == "m_end": + if key == "m_end": self.set_focus(len(self.walker) - 1) elif key == "m_start": self.set_focus(0) @@ -45,5 +43,5 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget): if self.master.options.console_focus_follow: self.walker.set_focus(len(self.walker) - 1) - def clear_events(self): + def sig_clear_log(self, sender): self.walker[:] = [] diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py index 343c46a65..b904f7067 100644 --- a/mitmproxy/tools/console/keymap.py +++ b/mitmproxy/tools/console/keymap.py @@ -6,6 +6,7 @@ from mitmproxy.tools.console import commandeditor SupportedContexts = { "chooser", "commands", + "eventlog", "flowlist", "flowview", "global", diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index d2575145e..ce4e4d9d0 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -426,6 +426,13 @@ class ConsoleAddon: ] ) + @command.command("console.eventlog.clear") + def eventlog_clear(self) -> None: + """ + Clear the event log. + """ + signals.sig_clear_log.send(self) + def running(self): self.started = True diff --git a/mitmproxy/tools/console/overlay.py b/mitmproxy/tools/console/overlay.py index 5a82a54b6..7072d00ec 100644 --- a/mitmproxy/tools/console/overlay.py +++ b/mitmproxy/tools/console/overlay.py @@ -118,6 +118,8 @@ class Chooser(urwid.WidgetWrap, layoutwidget.LayoutWidget): if key == "m_select": self.callback(self.choices[self.walker.index]) signals.pop_view_state.send(self) + elif key == "esc": + signals.pop_view_state.send(self) return super().keypress(size, key) diff --git a/mitmproxy/tools/console/signals.py b/mitmproxy/tools/console/signals.py index 2c09c708d..49115a5d8 100644 --- a/mitmproxy/tools/console/signals.py +++ b/mitmproxy/tools/console/signals.py @@ -1,6 +1,9 @@ import blinker -# Show a status message in the action bar +# Clear the eventlog +sig_clear_log = blinker.Signal() + +# Add an entry to the eventlog sig_add_log = blinker.Signal()