Commit 7af10503 authored by Lysander Trischler's avatar Lysander Trischler
Browse files

Fix indentation for actual conversation trees

twtxt.net doesn't support this at the moment, but in the future it might
be a real use case. Currently conversations are just linear and cannot
really break out into different branches like an e-mail thread, but
we've already got it covered.
parent 0721e99b
......@@ -24,11 +24,12 @@ class TwtsListBox(widgets.VimListBox):
items = []
def render(twt, level=0, more_siblings=False):
items.append(self.format_twt(twt, level, more_siblings))
def render(twt, level=0, indentation="", more_siblings=False):
widget, next_indentation = self.format_twt(twt, level, indentation, more_siblings)
items.append(widget)
self._twts.append(twt)
for i, reply in enumerate(twt.replies):
render(reply, level=level + 1, more_siblings=i < len(twt.replies) - 1)
render(reply, level=level + 1, indentation=next_indentation, more_siblings=i < len(twt.replies) - 1)
for twt in reversed(manager.conversation_tree):
render(twt)
......@@ -36,9 +37,10 @@ class TwtsListBox(widgets.VimListBox):
super().__init__(urwid.SimpleFocusListWalker(items))
def format_twt(self, twt, level, more_siblings):
def format_twt(self, twt, level, indentation, more_siblings):
created_at = "%s (%s)" % (twt.created_at.astimezone().strftime('%Y-%m-%d %H:%M'),
twt.relative_datetime \
.replace("seconds", "s") \
.replace("minutes", "m") \
.replace("minute", "m") \
.replace("hours", "h") \
......@@ -129,17 +131,20 @@ class TwtsListBox(widgets.VimListBox):
if level == 0:
next_indentation = ""
text = urwid.Text(markup)
else:
text = widgets.PrefixText(markup, prefix="├─" if more_siblings else "└─",
prefix_continuation="│ " if more_siblings else " ")
next_indentation = indentation + ("│ " if more_siblings else " ")
text = widgets.PrefixText(markup, prefix=indentation + ("├─" if more_siblings else "└─"),
prefix_continuation=next_indentation)
return widgets.SelectableAttrMap(urwid.Columns(filter(lambda x: x, [
return (widgets.SelectableAttrMap(urwid.Columns(filter(lambda x: x, [
(28, urwid.Text(created_at)),
(self._manager.max_author_nick_width, urwid.Text(nick, align="right")),
text]), dividechars=2),
twtxtrenderer.read_normal_map if twt.read else twtxtrenderer.unread_normal_map,
twtxtrenderer.read_focus_map if twt.read else twtxtrenderer.unread_focus_map)
twtxtrenderer.read_focus_map if twt.read else twtxtrenderer.unread_focus_map),
next_indentation)
def keypress(self, size, key):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment