diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 5da6ef0bd..397fc8e86 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -94,7 +94,8 @@ class ConsoleMaster(master.Master): self.start_err = entry else: signals.status_message.send( - message=(entry.level, "{}: {}".format(entry.level.title(), entry.msg)), + message=(entry.level, "{}: {}".format(entry.level.title(), + entry.msg.lstrip())), expire=5 ) diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index 8553a66ff..d4563515a 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -49,7 +49,7 @@ class ActionBar(urwid.WidgetWrap): def sig_message(self, sender, message, expire=1): if self.prompting: return - w = urwid.Text(message) + w = urwid.Text(self.prep_message(message)) self._w = w if expire: def cb(*args): @@ -60,6 +60,36 @@ class ActionBar(urwid.WidgetWrap): def prep_prompt(self, p): return p.strip() + ": " + def prep_message(self, msg): + cols, _ = self.master.ui.get_cols_rows() + eventlog_prompt = "(more in eventlog)" + if isinstance(msg, (tuple, list)): + log_level, msg_text = msg + elif isinstance(msg, str): + log_level, msg_text = None, msg + else: + return msg + + msg_lines = msg_text.split("\n") + first_line = msg_lines[0] + + def prep_line(line, eventlog_prompt, cols): + if cols < len(eventlog_prompt) + 3: + first_line = "..." + else: + first_line = line[:cols - len(eventlog_prompt) - 3] + "..." + return first_line + + if len(msg_lines) > 1: + if len(first_line) + len(eventlog_prompt) > cols: + first_line = prep_line(first_line, eventlog_prompt, cols) + else: + if len(first_line) > cols: + first_line = prep_line(first_line, eventlog_prompt, cols) + else: + eventlog_prompt = "" + return [(log_level, first_line), ("warn", eventlog_prompt)] + def sig_prompt(self, sender, prompt, text, callback, args=()): signals.focus.send(self, section="footer") self._w = urwid.Edit(self.prep_prompt(prompt), text or "")