Highlight hashtags
This commit is contained in:
parent
7da2e2dbbc
commit
dd1b462413
3 changed files with 24 additions and 11 deletions
|
@ -1,27 +1,25 @@
|
|||
# name, fg, bg, mono, fg_h, bg_h
|
||||
PALETTE = [
|
||||
# Header
|
||||
# Components
|
||||
('footer_message', 'dark green', ''),
|
||||
('footer_status', 'white', 'dark blue'),
|
||||
('footer_status_bold', 'white, bold', 'dark blue'),
|
||||
('header', 'white', '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
|
||||
('hashtag', 'light cyan,bold', ''),
|
||||
('link', ',italics', ''),
|
||||
|
||||
# by color name
|
||||
# Colors
|
||||
('blue', 'light blue', ''),
|
||||
('blue_bold', 'light blue, bold', ''),
|
||||
('blue_selected', 'white,bold', 'dark blue'),
|
||||
('cyan', 'dark cyan', ''),
|
||||
('cyan_bold', 'dark cyan,bold', ''),
|
||||
('gray', 'dark gray', ''),
|
||||
('green', 'dark green', ''),
|
||||
('green_selected', 'white,bold', 'dark green'),
|
||||
('italic', 'white', ''),
|
||||
('yellow', 'yellow', ''),
|
||||
('yellow_selected', 'yellow', 'dark blue'),
|
||||
('gray', 'light gray', ''),
|
||||
]
|
||||
|
|
|
@ -4,6 +4,7 @@ import webbrowser
|
|||
|
||||
from toot.utils import format_content
|
||||
|
||||
from .utils import highlight_hashtags
|
||||
from .widgets import SelectableText, SelectableColumns
|
||||
|
||||
logger = logging.getLogger("toot")
|
||||
|
@ -107,7 +108,7 @@ class StatusDetails(urwid.Pile):
|
|||
("gray", "Reblogged by "),
|
||||
("gray", status.data["account"]["display_name"])
|
||||
])
|
||||
yield urwid.Divider("-")
|
||||
yield urwid.AttrMap(urwid.Divider("-"), "gray")
|
||||
|
||||
if status.author.display_name:
|
||||
yield urwid.Text(("green", status.author.display_name))
|
||||
|
@ -115,7 +116,7 @@ class StatusDetails(urwid.Pile):
|
|||
yield urwid.Divider()
|
||||
|
||||
for line in format_content(status.data["content"]):
|
||||
yield urwid.Text(line)
|
||||
yield urwid.Text(highlight_hashtags(line))
|
||||
|
||||
if status.data["card"]:
|
||||
yield urwid.Divider()
|
||||
|
@ -125,6 +126,10 @@ class StatusDetails(urwid.Pile):
|
|||
yield urwid.Text(("green", card["title"].strip()))
|
||||
if card["author_name"]:
|
||||
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"]))
|
||||
|
||||
def build_card(self, card):
|
||||
|
|
10
toot/tui/utils.py
Normal file
10
toot/tui/utils.py
Normal 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)
|
||||
]
|
Loading…
Reference in a new issue