From fbdc7dce60987dc0833a0db031f6dca4f1e1fddc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Feb 2020 17:45:22 +0100 Subject: widgets/thread: add theming for quote lines in message body --- alot/widgets/thread.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'alot/widgets/thread.py') 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') -- cgit v1.2.3