Highlight hashtags

This commit is contained in:
Ivan Habunek 2018-01-21 15:45:07 +01:00
parent 3d44eeebba
commit cb1f7b4e61
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 16 additions and 0 deletions

View File

@ -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):

View File

@ -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