mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
console: console.eventlog.clear command, bind to "z" by default
This commit is contained in:
parent
9c57508fde
commit
a61178f28a
@ -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")
|
||||
|
@ -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[:] = []
|
||||
|
@ -6,6 +6,7 @@ from mitmproxy.tools.console import commandeditor
|
||||
SupportedContexts = {
|
||||
"chooser",
|
||||
"commands",
|
||||
"eventlog",
|
||||
"flowlist",
|
||||
"flowview",
|
||||
"global",
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user