From 49099ff222b5b41c4ea444c237622a338f477c28 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 2 Dec 2023 17:28:02 +0000 Subject: [PATCH] Show boosted toots sensibly. --- client.py | 10 ++++++++++ text.py | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client.py b/client.py index 5cec035..fae611c 100644 --- a/client.py +++ b/client.py @@ -76,6 +76,13 @@ class Client: class Status: def __init__(self, data): + rb = data.get('reblog') + if rb is not None: + self.booster = data['account'] + data = rb + else: + self.booster = None + self.post_id = data['id'] date, suffix = data['created_at'].split(".", 1) @@ -95,6 +102,9 @@ class Status: yield text.SeparatorLine(self.datestamp) yield text.FromLine('@' + self.account['acct'], self.account['display_name']) + if self.booster is not None: + yield text.BoosterLine('@' + self.booster['acct'], + self.booster['display_name']) yield text.BlankLine() yield from self.content yield text.BlankLine() diff --git a/text.py b/text.py index 7dc8905..dfa17eb 100644 --- a/text.py +++ b/text.py @@ -16,6 +16,7 @@ colourmap = { 'S': [0, 1, 7, 44, 37], 'D': [0, 7, 44, 37], 'F': [0, 1, 32], + 'f': [0, 32], 'c': [0, 33], '#': [0, 36], '@': [0, 32], @@ -99,15 +100,23 @@ class SeparatorLine: ColouredString("]--", 'S')) yield ColouredString("-", 'S') * (width - 1 - suffix.width) + suffix -class FromLine: +class UsernameHeader: def __init__(self, account, nameline): self.account = account self.nameline = nameline def render(self, width): # FIXME: truncate - yield (ColouredString("From: ") + - ColouredString(f"{self.nameline} ({self.account})", 'F')) + yield (ColouredString(self.header + ": ") + + ColouredString(f"{self.nameline} ({self.account})", + self.colour)) + +class FromLine(UsernameHeader): + header = "From" + colour = "F" +class BoosterLine(UsernameHeader): + header = "Via" + colour = "f" class Paragraph: def __init__(self): -- 2.30.2