reduce regex calls in name highlighting
This commit is contained in:
parent
d17d9ccf09
commit
070ed21dde
26
bink.py
26
bink.py
@ -142,18 +142,20 @@ class App():
|
|||||||
post_user = post["user"]
|
post_user = post["user"]
|
||||||
time_seconds = post["time"] / 1_000_000_000
|
time_seconds = post["time"] / 1_000_000_000
|
||||||
stamp = datetime.datetime.fromtimestamp(time_seconds)
|
stamp = datetime.datetime.fromtimestamp(time_seconds)
|
||||||
if current_user != post_user and name_re.search(body):
|
if current_user != post_user:
|
||||||
widget_body = []
|
search = name_re.finditer(body)
|
||||||
index = 0
|
if search:
|
||||||
for match in name_re.finditer(body):
|
widget_body = []
|
||||||
start, end = match.span()
|
index = 0
|
||||||
before = body[index:start]
|
for match in search:
|
||||||
highlight = body[start:end]
|
start, end = match.span()
|
||||||
widget_body.append(before)
|
before = body[index:start]
|
||||||
widget_body.append(("highlight", highlight))
|
highlight = body[start:end]
|
||||||
index = end
|
widget_body.append(before)
|
||||||
widget_body.append(body[index:])
|
widget_body.append(("highlight", highlight))
|
||||||
body = widget_body
|
index = end
|
||||||
|
widget_body.append(body[index:])
|
||||||
|
body = widget_body
|
||||||
pile = urwid.Pile([
|
pile = urwid.Pile([
|
||||||
urwid.Text([("bold", f"~{post_user}"), " @ ", stamp.strftime("%H:%M (%A, %B %d, %Y)")]),
|
urwid.Text([("bold", f"~{post_user}"), " @ ", stamp.strftime("%H:%M (%A, %B %d, %Y)")]),
|
||||||
urwid.Text(body),
|
urwid.Text(body),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user