summaryrefslogtreecommitdiff
path: root/alot/widgets/thread.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-02-17 17:45:22 +0100
committerAnton Khirnov <anton@khirnov.net>2020-02-19 16:00:44 +0100
commitfbdc7dce60987dc0833a0db031f6dca4f1e1fddc (patch)
tree7f130937b72919b9d0efef413a14e1326a22c15a /alot/widgets/thread.py
parentf063719d64bd4219cb8e1413f3e5a5812e663872 (diff)
widgets/thread: add theming for quote lines in message body
Diffstat (limited to 'alot/widgets/thread.py')
-rw-r--r--alot/widgets/thread.py35
1 files changed, 30 insertions, 5 deletions
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')