console: console.eventlog.clear command, bind to "z" by default

This commit is contained in:
Aldo Cortesi 2017-06-11 22:16:02 +12:00
parent 9c57508fde
commit a61178f28a
6 changed files with 19 additions and 6 deletions

View File

@ -135,3 +135,5 @@ def map(km):
"Read a Python-style escaped string from file" "Read a Python-style escaped string from file"
) )
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor") km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
km.add("z", "console.eventlog.clear", ["eventlog"], "Clear")

View File

@ -18,16 +18,14 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget):
self.master = master self.master = master
urwid.ListBox.__init__(self, self.walker) urwid.ListBox.__init__(self, self.walker)
signals.sig_add_log.connect(self.sig_add_log) signals.sig_add_log.connect(self.sig_add_log)
signals.sig_clear_log.connect(self.sig_clear_log)
def set_focus(self, index): def set_focus(self, index):
if 0 <= index < len(self.walker): if 0 <= index < len(self.walker):
super().set_focus(index) super().set_focus(index)
def keypress(self, size, key): def keypress(self, size, key):
if key == "z": if key == "m_end":
self.clear_events()
key = None
elif key == "m_end":
self.set_focus(len(self.walker) - 1) self.set_focus(len(self.walker) - 1)
elif key == "m_start": elif key == "m_start":
self.set_focus(0) self.set_focus(0)
@ -45,5 +43,5 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget):
if self.master.options.console_focus_follow: if self.master.options.console_focus_follow:
self.walker.set_focus(len(self.walker) - 1) self.walker.set_focus(len(self.walker) - 1)
def clear_events(self): def sig_clear_log(self, sender):
self.walker[:] = [] self.walker[:] = []

View File

@ -6,6 +6,7 @@ from mitmproxy.tools.console import commandeditor
SupportedContexts = { SupportedContexts = {
"chooser", "chooser",
"commands", "commands",
"eventlog",
"flowlist", "flowlist",
"flowview", "flowview",
"global", "global",

View File

@ -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): def running(self):
self.started = True self.started = True

View File

@ -118,6 +118,8 @@ class Chooser(urwid.WidgetWrap, layoutwidget.LayoutWidget):
if key == "m_select": if key == "m_select":
self.callback(self.choices[self.walker.index]) self.callback(self.choices[self.walker.index])
signals.pop_view_state.send(self) signals.pop_view_state.send(self)
elif key == "esc":
signals.pop_view_state.send(self)
return super().keypress(size, key) return super().keypress(size, key)

View File

@ -1,6 +1,9 @@
import blinker 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() sig_add_log = blinker.Signal()