diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-02-17 17:45:22 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-02-19 16:00:44 +0100 |
commit | fbdc7dce60987dc0833a0db031f6dca4f1e1fddc (patch) | |
tree | 7f130937b72919b9d0efef413a14e1326a22c15a | |
parent | f063719d64bd4219cb8e1413f3e5a5812e663872 (diff) |
widgets/thread: add theming for quote lines in message body
-rw-r--r-- | alot/defaults/default.theme | 10 | ||||
-rw-r--r-- | alot/defaults/theme.spec | 3 | ||||
-rw-r--r-- | alot/settings/manager.py | 4 | ||||
-rw-r--r-- | alot/settings/theme.py | 16 | ||||
-rw-r--r-- | alot/widgets/thread.py | 35 |
5 files changed, 63 insertions, 5 deletions
diff --git a/alot/defaults/default.theme b/alot/defaults/default.theme index b97dac50..0e3f796d 100644 --- a/alot/defaults/default.theme +++ b/alot/defaults/default.theme @@ -44,6 +44,16 @@ odd = 'default','','white','dark blue','white','#068' focus = 'standout','','white','light gray','#ff8','g58' + [[quote]] + [[[0]]] + body = 'default','','light green','default','light green','default' + [[[1]]] + body = 'default','','light red', 'default','light red', 'default' + [[[2]]] + body = 'default','','light magenta', 'default','light magenta', 'default' + [[[3]]] + body = 'default','','brown', 'default','brown', 'default' + [envelope] body = 'default','','light gray','default','light gray','default' header = 'default','','white','dark gray','white','dark gray' diff --git a/alot/defaults/theme.spec b/alot/defaults/theme.spec index 387bbe2a..352564a4 100644 --- a/alot/defaults/theme.spec +++ b/alot/defaults/theme.spec @@ -64,6 +64,9 @@ even = attrtriple odd = attrtriple focus = attrtriple + [[quote]] + [[[__many__]]] + body = attrtriple [envelope] body = attrtriple header = attrtriple diff --git a/alot/settings/manager.py b/alot/settings/manager.py index d9fa724d..f6da5332 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -311,6 +311,10 @@ class SettingsManager: colours = int(self._config.get('colourmode')) return self._theme.get_threadline_theming(thread, colours) + def get_quote_theming(self): + colours = int(self._config.get('colourmode')) + return self._theme.get_quote_theming(colours) + def get_tagstring_representation(self, tag, onebelow_normal=None, onebelow_focus=None): """ diff --git a/alot/settings/theme.py b/alot/settings/theme.py index 2794be2c..df34cba9 100644 --- a/alot/settings/theme.py +++ b/alot/settings/theme.py @@ -128,3 +128,19 @@ class Theme: res[part]['normal'] = pickcolour(fill('normal')) res[part]['focus'] = pickcolour(fill('focus')) return res + + def get_quote_theming(self, colourmode): + """ + Get a list of attributes to use for displaying successive levels of + nested quotes in a message body. + + :param colourmode: colourmode to use, one of 1,16,256. + :type colourmode: int + """ + idx = self._colours.index(colourmode) + mainsect = self._config['thread']['quote'] + + ret = [] + for sect in sorted(mainsect.sections): + ret.append(mainsect[sect]['body'][idx]) + return ret diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index ed2b5ac6..1954d84d 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -5,6 +5,7 @@ Widgets specific to thread mode """ import logging +import re import urwid from .globals import TagWidget @@ -150,6 +151,9 @@ class MessageWidget(urwid.WidgetWrap): _body_wgt = None _attach_wgt = None + _QUOTE_CHARS = '>|:}#' + _QUOTE_REGEX = '(([ \t]*[{quote_chars}])+)'.format(quote_chars = _QUOTE_CHARS) + def __init__(self, message, odd): """ :param message: Message to display @@ -200,11 +204,32 @@ class MessageWidget(urwid.WidgetWrap): return FocusableText(sourcetxt, att, att_focus) def _get_body(self): - bodytxt = self._message.get_body_text() - att = settings.get_theming_attribute('thread', 'body') - att_focus = settings.get_theming_attribute( - 'thread', 'body_focus') - return FocusableText(bodytxt, att, att_focus) + attr_body = settings.get_theming_attribute('thread', 'body') + attrs_quote = settings.get_quote_theming() + + body_lines = self._message.get_body_text().splitlines() + + quote_levels = [] + for line in body_lines: + level = 0 + m = re.match(self._QUOTE_REGEX, line) + if m is not None: + g = m.group(0) + for c in self._QUOTE_CHARS: + level += g.count(c) + + quote_levels.append(level) + + line_widgets = [] + + for level, line in zip(quote_levels, body_lines): + if level == 0 or len(attrs_quote) < 1: + attr = attr_body + else: + attr = attrs_quote[(level - 1) % len(attrs_quote)] + line_widgets.append(urwid.Text((attr, line))) + + return urwid.Pile(line_widgets) def _get_headers(self): key_attr = settings.get_theming_attribute('thread', 'header_key') |