Project: pygitweb

e497568 """Bottom status bar shared by all pages."""
from __future__ import annotations
8614508 from pyratatui import Constraint, Direction, Frame, Layout, Paragraph, Rect, Style
fc2f2ce _DEFAULT_HINT = "q quit"
8614508 def split_content_status(area: Rect) -> tuple[Rect, Rect]:
73c9c30 """Split the frame into content above a one-row status bar."""
chunks = Layout().direction(Direction.Vertical).constraints([Constraint.fill(1), Constraint.length(1)]).split(area)
return chunks[0], chunks[1]
e497568
8614508 def render_status_bar(
73c9c30 frame: Frame,
area: Rect,
text: str,
style: Style,
hint: str = _DEFAULT_HINT,
8614508 ) -> None:
73c9c30 """Draw the status bar into ``area``."""
if area.width <= 0 or area.height <= 0:
return
line = _format_line(text, hint, area.width)
frame.render_widget(Paragraph.from_string(line).style(style), area)
e497568
def _format_line(left: str, right: str, width: int) -> str:
73c9c30 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)