Shortening notifications in statusbar

This commit is contained in:
Miroslav 2018-02-28 00:18:18 +02:00
parent 9016608486
commit 5161458217
2 changed files with 33 additions and 2 deletions

View File

@ -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
)

View File

@ -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 "")