mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Improve print_instance
This commit is contained in:
parent
1b84f34123
commit
6833607984
@ -3,13 +3,13 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
from wcwidth import wcswidth
|
|
||||||
from toot.tui.utils import parse_datetime
|
from toot.tui.utils import parse_datetime
|
||||||
|
from wcwidth import wcswidth
|
||||||
|
|
||||||
from toot.utils import format_content, get_text, parse_html
|
from toot.utils import get_text, parse_html
|
||||||
from toot.wcstring import wc_wrap
|
from toot.wcstring import wc_wrap
|
||||||
|
|
||||||
|
|
||||||
@ -88,17 +88,28 @@ def print_instance(instance):
|
|||||||
print_out("<green>{}</green>".format(instance['title']))
|
print_out("<green>{}</green>".format(instance['title']))
|
||||||
print_out("<blue>{}</blue>".format(instance['uri']))
|
print_out("<blue>{}</blue>".format(instance['uri']))
|
||||||
print_out("running Mastodon {}".format(instance['version']))
|
print_out("running Mastodon {}".format(instance['version']))
|
||||||
print_out("")
|
print_out()
|
||||||
|
|
||||||
description = instance['description'].strip()
|
description = instance.get("description")
|
||||||
if not description:
|
if description:
|
||||||
return
|
for paragraph in re.split(r"[\r\n]+", description.strip()):
|
||||||
|
paragraph = get_text(paragraph)
|
||||||
|
print_out(textwrap.fill(paragraph, width=80))
|
||||||
|
print_out()
|
||||||
|
|
||||||
lines = [line.strip() for line in format_content(description) if line.strip()]
|
rules = instance.get("rules")
|
||||||
for line in lines:
|
if rules:
|
||||||
for l in wrap(line.strip()):
|
print_out("Rules:")
|
||||||
print_out(l)
|
for ordinal, rule in enumerate(rules):
|
||||||
print_out()
|
ordinal = f"{ordinal + 1}."
|
||||||
|
lines = textwrap.wrap(rule["text"], 80 - len(ordinal))
|
||||||
|
first = True
|
||||||
|
for line in lines:
|
||||||
|
if first:
|
||||||
|
print_out(f"{ordinal} {line}")
|
||||||
|
first = False
|
||||||
|
else:
|
||||||
|
print_out(f"{' ' * len(ordinal)} {line}")
|
||||||
|
|
||||||
|
|
||||||
def print_account(account):
|
def print_account(account):
|
||||||
|
Loading…
Reference in New Issue
Block a user