From 279b8316341841dd32bdda5a21bb61fed8b9d1ef Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 8 Feb 2020 20:54:38 +0100 Subject: thread: implement tree decorations They were temporarily removed in the previous commit. Still not working: - theming for the decorations - drawing the connector line properly for expanded messages - configurable indentation --- alot/widgets/thread.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'alot/widgets/thread.py') diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 0b4e2404..ebbc4704 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -290,3 +290,56 @@ class MessageWidget(urwid.WidgetWrap): matches given `querystring` """ self.display_content = not self._message.matches(querystring) + +class ThreadNode(urwid.WidgetWrap): + _ARROW = '➤' + _HBAR = '─' + _VBAR = '│' + _TNODE = '├' + _CORNER = '└' + + _decor_text = None + _have_next_sibling = None + + def __init__(self, msg_wgt, thread, pos, indent): + msg = msg_wgt.get_message() + + if msg.depth == 0: + wgt = msg_wgt + else: + self._decor_text = urwid.Text('') + wgt = urwid.Columns([('pack', self._decor_text), msg_wgt]) + + ancestor_chain = [msg] + for p in msg.parents(): + ancestor_chain.insert(0, p) + + have_sibling = [] + for d, m in enumerate(ancestor_chain): + if d == 0: + have_sibling.append(m != thread.toplevel_messages[-1]) + else: + have_sibling.append(m != ancestor_chain[d - 1].replies[-1]) + + self._have_next_sibling = have_sibling + + super().__init__(wgt) + + self.set_indent(indent) + + def set_indent(self, indent): + if self._decor_text is None: + return + + seg_text = [] + if indent > 0: + depth = len(self._have_next_sibling) - 1 + for d in range(depth): + if d == depth - 1: + corner = self._TNODE if self._have_next_sibling[d + 1] else self._CORNER + seg_text.append(corner + self._ARROW) + else: + bar = self._VBAR if self._have_next_sibling[d + 1] else ' ' + seg_text.append(bar + ' ') + + self._decor_text.set_text(''.join(seg_text)) -- cgit v1.2.3