Account overlay is now at feature parity with toot whois command

This commit is contained in:
Daniel Schwarz 2023-02-02 20:37:12 -05:00 committed by Ivan Habunek
parent e10fff983f
commit a5d61c04a7

View file

@ -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)