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"]
|
||||
time_seconds = post["time"] / 1_000_000_000
|
||||
stamp = datetime.datetime.fromtimestamp(time_seconds)
|
||||
if current_user != post_user and name_re.search(body):
|
||||
widget_body = []
|
||||
index = 0
|
||||
for match in name_re.finditer(body):
|
||||
start, end = match.span()
|
||||
before = body[index:start]
|
||||
highlight = body[start:end]
|
||||
widget_body.append(before)
|
||||
widget_body.append(("highlight", highlight))
|
||||
index = end
|
||||
widget_body.append(body[index:])
|
||||
body = widget_body
|
||||
if current_user != post_user:
|
||||
search = name_re.finditer(body)
|
||||
if search:
|
||||
widget_body = []
|
||||
index = 0
|
||||
for match in search:
|
||||
start, end = match.span()
|
||||
before = body[index:start]
|
||||
highlight = body[start:end]
|
||||
widget_body.append(before)
|
||||
widget_body.append(("highlight", highlight))
|
||||
index = end
|
||||
widget_body.append(body[index:])
|
||||
body = widget_body
|
||||
pile = urwid.Pile([
|
||||
urwid.Text([("bold", f"~{post_user}"), " @ ", stamp.strftime("%H:%M (%A, %B %d, %Y)")]),
|
||||
urwid.Text(body),
|
||||
|
Loading…
x
Reference in New Issue
Block a user