From: Simon Tatham Date: Mon, 11 Dec 2023 19:11:04 +0000 (+0000) Subject: Post info: add list of mentioned users. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=fe28194c25084ebf83f15145f7c769085bea18d0;p=mastodonochrome.git Post info: add list of mentioned users. Because the post itself doesn't show their fully qualified usernames. --- diff --git a/client.py b/client.py index 856bd94..8206af6 100644 --- a/client.py +++ b/client.py @@ -404,7 +404,7 @@ class Status: sensitive = "yes" if self.data['sensitive'] else "no" yield text.Paragraph("Sensitive: " + sensitive) spoiler = noneify(self.data['spoiler_text'], include_empty=True) - yield text.Paragraph("Spoiler text: " + spoiler) + yield text.IndentedParagraph(0, 2, "Spoiler text: " + spoiler) yield text.BlankLine() replies = str(self.data['replies_count']) @@ -415,11 +415,19 @@ class Status: yield text.Paragraph("Favourites: " + faves) yield text.BlankLine() + if len(self.mentions) > 0: + yield text.Paragraph("Mentioned user:") + for mention in self.mentions: + yield text.IndentedParagraph(2, 4, text.ColouredString( + self.client.fq(mention['acct']), 'f')) + yield text.BlankLine() + app_subdict = self.data.get('application', {}) client = noneify(app_subdict.get('name')) yield text.Paragraph("Client name: " + client) client_url = noneify(app_subdict.get('website'), colour='u') yield text.Paragraph("Client website: " + client_url) + yield text.BlankLine() def get_reply_recipients(self): yield self.client.fq(self.account['acct']) diff --git a/text.py b/text.py index 42f70d0..378b5fc 100644 --- a/text.py +++ b/text.py @@ -383,6 +383,21 @@ class Paragraph: def __repr__(self): return f"Paragraph({self.words!r}, unfinished={self.unfinished_word!r})" +class IndentedParagraph(Paragraph): + def __init__(self, firstindent, laterindent, text=None): + super().__init__(text) + self.firstindent = firstindent + self.laterindent = laterindent + + def render(self, width): + it = super().render(width - self.firstindent, width - self.laterindent) + try: + yield " " * self.firstindent + next(it) + except StopIteration: + return + for line in it: + yield " " * self.laterindent + next(it) + class NotificationLog: can_highlight_as_target = True