From 8c33418c97a5bf37819c2344f9750e19b1bf192f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 May 2020 10:06:34 +0200 Subject: widgets/thread: factor out quote parsing --- alot/widgets/thread.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'alot/widgets/thread.py') diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 631d6abe..78d974f2 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -191,24 +191,8 @@ class _TextPart(_MIMEPartWidget): attrs_quote = settings.get_quote_theming() fold_context = settings.get('thread_fold_context') - lines = text.splitlines() - - blocks = [] - max_level = 0 - for line in 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) - - max_level = max(max_level, level) - - if len(blocks) > 0 and blocks[-1][0] == level: - blocks[-1][1].append(line) - else: - blocks.append((level, [line])) + blocks = self._split_quotes(text) + max_level = max((b[0] for b in blocks)) block_wgts = [] for level, lines in blocks: @@ -225,6 +209,28 @@ class _TextPart(_MIMEPartWidget): super().__init__(urwid.Pile(block_wgts)) + def _split_quotes(self, text): + """ + Split the text into blocks of quote levels. + """ + lines = text.splitlines() + + blocks = [] + for line in 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) + + if len(blocks) > 0 and blocks[-1][0] == level: + blocks[-1][1].append(line) + else: + blocks.append((level, [line])) + + return blocks + @property def foldlevel(self): return self._fold_level -- cgit v1.2.3