From dd1b4624133da54213b5f3e7fc7f9fdec952ac49 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 24 Aug 2019 14:14:46 +0200 Subject: [PATCH] Highlight hashtags --- toot/tui/constants.py | 16 +++++++--------- toot/tui/timeline.py | 9 +++++++-- toot/tui/utils.py | 10 ++++++++++ 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 toot/tui/utils.py diff --git a/toot/tui/constants.py b/toot/tui/constants.py index 904a09c..df9b511 100644 --- a/toot/tui/constants.py +++ b/toot/tui/constants.py @@ -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', ''), ] diff --git a/toot/tui/timeline.py b/toot/tui/timeline.py index 49699fb..29d0cfd 100644 --- a/toot/tui/timeline.py +++ b/toot/tui/timeline.py @@ -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): diff --git a/toot/tui/utils.py b/toot/tui/utils.py new file mode 100644 index 0000000..0f302c5 --- /dev/null +++ b/toot/tui/utils.py @@ -0,0 +1,10 @@ +import re + +HASHTAG_PATTERN = re.compile(r'(?