From a5d61c04a7d181d5f729784f86efba38c1142b75 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 2 Feb 2023 20:37:12 -0500 Subject: [PATCH] Account overlay is now at feature parity with toot whois command --- toot/tui/overlays.py | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index 6623329..623dbe8 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -4,8 +4,8 @@ import urwid import webbrowser from toot import __version__ - -from .utils import highlight_keys +from toot.utils import format_content +from .utils import highlight_hashtags, highlight_keys from .widgets import Button, EditBox, SelectableText @@ -207,3 +207,53 @@ class Help(urwid.Padding): yield urwid.Divider() yield link("Documentation: ", "https://toot.readthedocs.io/") yield link("Project home: ", "https://github.com/ihabunek/toot/") + + +class Account(urwid.ListBox): + """Shows account data and provides various actions""" + def __init__(self, account): + self.account = account + actions = list(self.generate_contents()) + walker = urwid.SimpleListWalker(actions) + super().__init__(walker) + + def generate_contents(self): + account = self.account + + def link(text, url): + attr_map = {"link": "link_focused"} + text = SelectableText([text, ("link", url)]) + urwid.connect_signal(text, "click", lambda t: webbrowser.open(url)) + return urwid.AttrMap(text, "", attr_map) + + +# source = json.dumps(account, indent=4) + yield urwid.Text([('green', f"@{account['acct']}"), (f" {account['display_name']}")]) + + if account["note"]: + yield urwid.Divider() + for line in format_content(account["note"]): + yield urwid.Text(highlight_hashtags(line, followed_tags=set())) + + yield urwid.Divider() + yield urwid.Text([("ID: "), ("green", f"{account['id']}")]) + yield urwid.Text([("Since: "), ("green", f"{account['created_at'][:10]}")]) + yield urwid.Divider() + yield urwid.Text([("Followers: "), ("yellow", f"{account['followers_count']}")]) + yield urwid.Text([("Following: "), ("yellow", f"{account['following_count']}")]) + yield urwid.Text([("Statuses: "), ("yellow", f"{account['statuses_count']}")]) + + if account["fields"]: + for field in account["fields"]: + name = field["name"].title() + yield urwid.Divider() + yield urwid.Text([("yellow", f"{name}"), (":")]) + for line in format_content(field["value"]): + yield urwid.Text(highlight_hashtags(line, followed_tags=set())) + if field["verified_at"]: + yield urwid.Text(("green", "✓ Verified")) + + yield urwid.Divider() + yield link("", account["url"]) + +# yield urwid.Text(source)