1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Highlight hashtags

This commit is contained in:
Ivan Habunek 2019-08-24 14:14:46 +02:00
parent 7da2e2dbbc
commit dd1b462413
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
3 changed files with 24 additions and 11 deletions

View File

@ -1,27 +1,25 @@
# name, fg, bg, mono, fg_h, bg_h # name, fg, bg, mono, fg_h, bg_h
PALETTE = [ PALETTE = [
# Header # Components
('footer_message', 'dark green', ''),
('footer_status', 'white', 'dark blue'),
('footer_status_bold', 'white, bold', 'dark blue'),
('header', 'white', 'dark blue'), ('header', 'white', 'dark blue'),
('header_bold', 'white,bold', 'dark blue'), ('header_bold', 'white,bold', 'dark blue'),
# Footer
('footer_status', 'white', 'dark blue'),
('footer_status_bold', 'white, bold', 'dark blue'),
('footer_message', 'dark green', ''),
# Functional # Functional
('hashtag', 'light cyan,bold', ''),
('link', ',italics', ''), ('link', ',italics', ''),
# by color name # Colors
('blue', 'light blue', ''), ('blue', 'light blue', ''),
('blue_bold', 'light blue, bold', ''), ('blue_bold', 'light blue, bold', ''),
('blue_selected', 'white,bold', 'dark blue'), ('blue_selected', 'white,bold', 'dark blue'),
('cyan', 'dark cyan', ''), ('cyan', 'dark cyan', ''),
('cyan_bold', 'dark cyan,bold', ''), ('cyan_bold', 'dark cyan,bold', ''),
('gray', 'dark gray', ''),
('green', 'dark green', ''), ('green', 'dark green', ''),
('green_selected', 'white,bold', 'dark green'), ('green_selected', 'white,bold', 'dark green'),
('italic', 'white', ''),
('yellow', 'yellow', ''), ('yellow', 'yellow', ''),
('yellow_selected', 'yellow', 'dark blue'), ('yellow_selected', 'yellow', 'dark blue'),
('gray', 'light gray', ''),
] ]

View File

@ -4,6 +4,7 @@ import webbrowser
from toot.utils import format_content from toot.utils import format_content
from .utils import highlight_hashtags
from .widgets import SelectableText, SelectableColumns from .widgets import SelectableText, SelectableColumns
logger = logging.getLogger("toot") logger = logging.getLogger("toot")
@ -107,7 +108,7 @@ class StatusDetails(urwid.Pile):
("gray", "Reblogged by "), ("gray", "Reblogged by "),
("gray", status.data["account"]["display_name"]) ("gray", status.data["account"]["display_name"])
]) ])
yield urwid.Divider("-") yield urwid.AttrMap(urwid.Divider("-"), "gray")
if status.author.display_name: if status.author.display_name:
yield urwid.Text(("green", status.author.display_name)) yield urwid.Text(("green", status.author.display_name))
@ -115,7 +116,7 @@ class StatusDetails(urwid.Pile):
yield urwid.Divider() yield urwid.Divider()
for line in format_content(status.data["content"]): for line in format_content(status.data["content"]):
yield urwid.Text(line) yield urwid.Text(highlight_hashtags(line))
if status.data["card"]: if status.data["card"]:
yield urwid.Divider() yield urwid.Divider()
@ -125,6 +126,10 @@ class StatusDetails(urwid.Pile):
yield urwid.Text(("green", card["title"].strip())) yield urwid.Text(("green", card["title"].strip()))
if card["author_name"]: if card["author_name"]:
yield urwid.Text(["by ", ("yellow", card["author_name"].strip())]) yield urwid.Text(["by ", ("yellow", card["author_name"].strip())])
yield urwid.Text("")
if card["description"]:
yield urwid.Text(card["description"].strip())
yield urwid.Text("")
yield urwid.Text(("link", card["url"])) yield urwid.Text(("link", card["url"]))
def build_card(self, card): def build_card(self, card):

10
toot/tui/utils.py Normal file
View File

@ -0,0 +1,10 @@
import re
HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
def highlight_hashtags(line):
return [
("hashtag", p) if p.startswith("#") else p
for p in re.split(HASHTAG_PATTERN, line)
]