Project: pygitweb

97c4910 """Tab bar rendering for the home page header."""
from __future__ import annotations
8614508 from pyratatui import Constraint, Direction, Frame, Layout, Paragraph, Rect, Tabs
8614508 from pygittools.tui.git_colors import active_tab_style, current_theme, focus_style
def init_tab_colors() -> None:
73c9c30 """Refresh cached tab attributes from the active Git color theme."""
return None
97c4910
8614508 def render_tab_row(
73c9c30 frame: Frame,
area: Rect,
prefix: str,
tab_labels: tuple[str, ...],
active_index: int,
*,
prefix_focused: bool = False,
97c4910 ) -> None:
73c9c30 """Draw project prefix and selectable tabs into ``area``."""
if area.height <= 0 or area.width <= 0:
return
theme = current_theme()
prefix_style = focus_style(theme.branch) if prefix_focused else theme.branch
prefix_width = min(area.width, len(prefix) + 2)
chunks = (
Layout()
.direction(Direction.Horizontal)
.constraints([Constraint.length(prefix_width), Constraint.fill(1)])
.split(area)
)
frame.render_widget(Paragraph.from_string(prefix).style(prefix_style), chunks[0])
frame.render_widget(
Tabs(list(tab_labels))
.select(active_index)
.highlight_style(active_tab_style())
.style(theme.tab_inactive)
.divider(" "),
chunks[1],
)