Removed followed_tags highlight feature (incompatible with HTML render)
Also converted polls.py to use HTML rendering
This commit is contained in:
parent
86304dfef0
commit
4c51220dc4
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Remote Attach",
|
||||
"type": "python",
|
||||
"request": "attach",
|
||||
"connect": {
|
||||
"host": "localhost",
|
||||
"port": 9000
|
||||
},
|
||||
"pathMappings": [
|
||||
{
|
||||
"localRoot": "${workspaceFolder}",
|
||||
"remoteRoot": "."
|
||||
}
|
||||
],
|
||||
"justMyCode": false
|
||||
}
|
||||
]
|
||||
}
|
|
@ -6,3 +6,4 @@ sphinx
|
|||
sphinx-autobuild
|
||||
twine
|
||||
wheel
|
||||
debugpy
|
||||
|
|
|
@ -10,6 +10,7 @@ from itertools import chain
|
|||
from toot import config, commands, CLIENT_NAME, CLIENT_WEBSITE, __version__
|
||||
from toot.exceptions import ApiError, ConsoleError
|
||||
from toot.output import print_out, print_err
|
||||
from .debugger import initialize_debugger
|
||||
|
||||
VISIBILITY_CHOICES = ["public", "unlisted", "private", "direct"]
|
||||
VISIBILITY_CHOICES_STR = ", ".join(f"'{v}'" for v in VISIBILITY_CHOICES)
|
||||
|
@ -178,6 +179,12 @@ common_args = [
|
|||
"action": 'store_true',
|
||||
"default": False,
|
||||
}),
|
||||
(["--debugger"], {
|
||||
"help": "launch with vscode debugpy",
|
||||
"action": 'store_true',
|
||||
"default": False,
|
||||
}),
|
||||
|
||||
]
|
||||
|
||||
# Arguments added to commands which require authentication
|
||||
|
@ -901,6 +908,9 @@ def run_command(app, user, name, args):
|
|||
|
||||
|
||||
def main():
|
||||
if "--debugger" in sys.argv:
|
||||
initialize_debugger()
|
||||
|
||||
# Enable debug logging if --debug is in args
|
||||
if "--debug" in sys.argv:
|
||||
filename = os.getenv("TOOT_LOG_FILE")
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
def initialize_debugger():
|
||||
import multiprocessing
|
||||
|
||||
if multiprocessing.current_process().pid > 1:
|
||||
import debugpy
|
||||
|
||||
debugpy.listen(("0.0.0.0", 9000))
|
||||
print("VSCode Debugger is ready to be attached on port 9000, press F5", flush=True)
|
||||
debugpy.wait_for_client()
|
||||
print("VSCode Debugger is now attached", flush=True)
|
|
@ -120,7 +120,6 @@ class TUI(urwid.Frame):
|
|||
def run(self):
|
||||
self.loop.set_alarm_in(0, lambda *args: self.async_load_instance())
|
||||
self.loop.set_alarm_in(0, lambda *args: self.async_load_followed_accounts())
|
||||
self.loop.set_alarm_in(0, lambda *args: self.async_load_followed_tags())
|
||||
self.loop.set_alarm_in(0, lambda *args: self.async_load_timeline(
|
||||
is_initial=True, timeline_name="home"))
|
||||
self.loop.run()
|
||||
|
@ -316,22 +315,6 @@ class TUI(urwid.Frame):
|
|||
|
||||
self.run_in_thread(_load_accounts, done_callback=_done_accounts)
|
||||
|
||||
def async_load_followed_tags(self):
|
||||
def _load_tag_list():
|
||||
try:
|
||||
return api.followed_tags(self.app, self.user)
|
||||
except ApiError:
|
||||
# not supported by all Mastodon servers so fail silently if necessary
|
||||
return []
|
||||
|
||||
def _done_tag_list(tags):
|
||||
if len(tags) > 0:
|
||||
self.followed_tags = [t["name"] for t in tags]
|
||||
else:
|
||||
self.followed_tags = []
|
||||
|
||||
self.run_in_thread(_load_tag_list, done_callback=_done_tag_list)
|
||||
|
||||
def refresh_footer(self, timeline):
|
||||
"""Show status details in footer."""
|
||||
status, index, count = timeline.get_focused_status_with_counts()
|
||||
|
|
|
@ -2,9 +2,9 @@ import urwid
|
|||
|
||||
from toot import api
|
||||
from toot.exceptions import ApiError
|
||||
from toot.utils import format_content
|
||||
from .utils import highlight_hashtags, parse_datetime
|
||||
from .utils import parse_datetime
|
||||
from .widgets import Button, CheckBox, RadioButton
|
||||
from .richtext import ContentParser
|
||||
|
||||
|
||||
class Poll(urwid.ListBox):
|
||||
|
@ -85,8 +85,12 @@ class Poll(urwid.ListBox):
|
|||
|
||||
def generate_contents(self, status):
|
||||
yield urwid.Divider()
|
||||
for line in format_content(status.data["content"]):
|
||||
yield urwid.Text(highlight_hashtags(line, set()))
|
||||
|
||||
parser = ContentParser()
|
||||
widgetlist = parser.html_to_widgets(status.data["content"])
|
||||
|
||||
for line in widgetlist:
|
||||
yield (line)
|
||||
|
||||
yield urwid.Divider()
|
||||
yield self.build_linebox(self.generate_poll_detail())
|
||||
|
|
|
@ -313,7 +313,6 @@ class Timeline(urwid.Columns):
|
|||
class StatusDetails(urwid.Pile):
|
||||
def __init__(self, timeline: Timeline, status: Optional[Status]):
|
||||
self.status = status
|
||||
self.followed_tags = timeline.tui.followed_tags
|
||||
self.followed_accounts = timeline.tui.followed_accounts
|
||||
|
||||
reblogged_by = status.author if status and status.reblog else None
|
||||
|
|
|
@ -81,21 +81,6 @@ def highlight_keys(text, high_attr, low_attr=""):
|
|||
return list(_gen())
|
||||
|
||||
|
||||
def highlight_hashtags(line, followed_tags, attr="hashtag", followed_attr="followed_hashtag"):
|
||||
hline = []
|
||||
|
||||
for p in re.split(HASHTAG_PATTERN, line):
|
||||
if p.startswith("#"):
|
||||
if p[1:].lower() in (t.lower() for t in followed_tags):
|
||||
hline.append((followed_attr, p))
|
||||
else:
|
||||
hline.append((attr, p))
|
||||
else:
|
||||
hline.append(p)
|
||||
|
||||
return hline
|
||||
|
||||
|
||||
def show_media(paths):
|
||||
"""
|
||||
Attempt to open an image viewer to show given media files.
|
||||
|
|
Loading…
Reference in New Issue