summaryrefslogtreecommitdiff
path: root/alot/widgets/thread.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-02-08 20:54:38 +0100
committerAnton Khirnov <anton@khirnov.net>2020-02-19 16:00:44 +0100
commit279b8316341841dd32bdda5a21bb61fed8b9d1ef (patch)
treed35fd36b6a887351c4c9dd198e337b8148c34423 /alot/widgets/thread.py
parentd25d788bdcf91f4066ae8e80ef7aebe85213d4d3 (diff)
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
Diffstat (limited to 'alot/widgets/thread.py')
-rw-r--r--alot/widgets/thread.py53
1 files changed, 53 insertions, 0 deletions
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))