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
"""Bottom status bar shared by all pages."""
from __future__ import annotations
from unicurses import mvaddstr # type: ignore[import-untyped]
_DEFAULT_HINT = "q quit"
def content_height(full_height: int) -> int:
"""Rows available to page content above the status bar."""
return max(0, full_height - 1)
def draw_status_bar(row: int, width: int, text: str, attr: int, hint: str = _DEFAULT_HINT) -> None:
"""Draw the status bar on the last screen row."""
if width <= 0:
return
line = _format_line(text, hint, width)
mvaddstr(row, 0, line, attr)
def _format_line(left: str, right: str, width: int) -> str:
if not right:
return left[:width].ljust(width)
if len(right) >= width:
return right[:width].ljust(width)
space = width - len(right)
if space <= 1:
return right[:width].ljust(width)
clipped_left = left[: space - 1]
return f"{clipped_left:<{space - 1}} {right}"[:width].ljust(width)