1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""unicurses drawing helpers."""
from __future__ import annotations
from pygittools.tui.ucurses import clrtoeol, move, mvaddstr # type: ignore[import-untyped]
def clear_row(row: int) -> None:
"""Clear a screen row before multi-segment redraws."""
move(row, 0)
clrtoeol()
def draw_text(row: int, col: int, text: str, width: int, attr: int = 0) -> int:
"""Write ``text`` at ``col`` without clearing the rest of the row."""
if col >= width or not text:
return col
clipped = text[: max(0, width - col - 1)]
if not clipped:
return col
move(row, col)
if attr:
mvaddstr(row, col, clipped, attr)
else:
mvaddstr(row, col, clipped)
return col + len(clipped)
def draw_line(row: int, col: int, text: str, width: int, attr: int = 0) -> None:
"""Write ``text`` on one row, clipped to the terminal width."""
if col == 0:
clear_row(row)
draw_text(row, col, text, width, attr)