Introduction
Introduction Statistics Contact Development Disclaimer Help
Highlight hashtags - toot - Unnamed repository; edit this file 'description' to…
Log
Files
Refs
LICENSE
---
commit cb1f7b4e61e66ceecf91fe286ac9f44166ef3b25
parent 3d44eeebba8c0bc166764d2f75dfa5c5ad12a200
Author: Ivan Habunek <[email protected]>
Date: Sun, 21 Jan 2018 15:45:07 +0100
Highlight hashtags
Diffstat:
toot/ui/app.py | 2 ++
toot/ui/utils.py | 14 ++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/toot/ui/app.py b/toot/ui/app.py
@@ -36,6 +36,8 @@ class Color:
class_.WHITE_ON_BLUE = curses.color_pair(8)
class_.WHITE_ON_RED = curses.color_pair(9)
+ class_.HASHTAG = class_.BLUE | curses.A_BOLD
+
class HeaderWindow:
def __init__(self, height, width, y, x):
diff --git a/toot/ui/utils.py b/toot/ui/utils.py
@@ -1,3 +1,5 @@
+import re
+
from textwrap import wrap
@@ -33,6 +35,17 @@ def enumerate_lines(lines, text_width, default_color):
return enumerate(wrap_lines(lines))
+HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
+
+
+def highlight_hashtags(window, y, padding, line):
+ from toot.ui.app import Color
+
+ for match in re.finditer(HASHTAG_PATTERN, line):
+ start, end = match.span()
+ window.chgat(y, start + padding, end - start, Color.HASHTAG)
+
+
def draw_lines(window, lines, start_y, padding, default_color):
height, width = window.getmaxyx()
text_width = width - 2 * padding
@@ -41,5 +54,6 @@ def draw_lines(window, lines, start_y, padding, default_color…
y = start_y + dy
if y < height - 1:
window.addstr(y, padding, line.ljust(text_width), color)
+ highlight_hashtags(window, y, padding, line)
return y + 1
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.