feat: Apply a distinct background color to firehose lines.
This commit is contained in:
@@ -15,9 +15,10 @@ from engine.render import big_wrap, lr_gradient, make_block
|
|||||||
from engine.effects import noise, glitch_bar, fade_line, vis_trunc, next_headline, firehose_line
|
from engine.effects import noise, glitch_bar, fade_line, vis_trunc, next_headline, firehose_line
|
||||||
|
|
||||||
_ANSI_LINE_RE = re.compile(r"^(\033\[[0-9;]*m)(.*)(\033\[0m)$")
|
_ANSI_LINE_RE = re.compile(r"^(\033\[[0-9;]*m)(.*)(\033\[0m)$")
|
||||||
|
FIREHOSE_BG = "\033[48;5;233m"
|
||||||
|
|
||||||
|
|
||||||
def _overlay_segments(ansi_line):
|
def _overlay_segments(ansi_line, bg=""):
|
||||||
"""Return (1-indexed column, colored chunk) for non-space runs in a line."""
|
"""Return (1-indexed column, colored chunk) for non-space runs in a line."""
|
||||||
m = _ANSI_LINE_RE.match(ansi_line)
|
m = _ANSI_LINE_RE.match(ansi_line)
|
||||||
if m:
|
if m:
|
||||||
@@ -34,7 +35,10 @@ def _overlay_segments(ansi_line):
|
|||||||
while j < len(text) and text[j] != " ":
|
while j < len(text) and text[j] != " ":
|
||||||
j += 1
|
j += 1
|
||||||
chunk = text[i:j]
|
chunk = text[i:j]
|
||||||
segs.append((i + 1, f"{color}{chunk}{RST}" if color else chunk))
|
if bg or color:
|
||||||
|
segs.append((i + 1, f"{bg}{color}{chunk}{RST}"))
|
||||||
|
else:
|
||||||
|
segs.append((i + 1, chunk))
|
||||||
i = j
|
i = j
|
||||||
return segs
|
return segs
|
||||||
|
|
||||||
@@ -223,7 +227,9 @@ def stream(items, ntfy_poller, mic_monitor):
|
|||||||
scr_row = firehose_top + fr + 1
|
scr_row = firehose_top + fr + 1
|
||||||
if scr_row <= msg_h or scr_row > h:
|
if scr_row <= msg_h or scr_row > h:
|
||||||
continue
|
continue
|
||||||
for col, chunk in _overlay_segments(fline):
|
# Opaque row backdrop to distinguish firehose from ticker beneath it.
|
||||||
|
buf.append(f"\033[{scr_row};1H{FIREHOSE_BG}{' ' * w}{RST}")
|
||||||
|
for col, chunk in _overlay_segments(fline, FIREHOSE_BG):
|
||||||
buf.append(f"\033[{scr_row};{col}H{chunk}")
|
buf.append(f"\033[{scr_row};{col}H{chunk}")
|
||||||
|
|
||||||
sys.stdout.buffer.write("".join(buf).encode())
|
sys.stdout.buffer.write("".join(buf).encode())
|
||||||
|
|||||||
Reference in New Issue
Block a user