Coverage for src / lilbee / cli / tui / pill.py: 100%
9 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-04-29 19:16 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-04-29 19:16 +0000
1"""Pill badge — colored inline label using half-block characters.
3Ported from toad (https://github.com/batrachianai/toad).
4"""
6from textual.content import Content
8PILL_LEFT = "▌" # left half block
9PILL_RIGHT = "▐" # right half block
10DOT_SEP = " \u00b7 " # middle dot separator for inline dividers
13def pill(text: Content | str, background: str, foreground: str) -> Content:
14 """Format text as a pill badge with rounded half-block ends.
15 Args:
16 text: Pill contents.
17 background: Background color (Textual color string, e.g. "$primary").
18 foreground: Foreground color (Textual color string, e.g. "$text").
20 Returns:
21 Styled Content with half-block ends.
22 """
23 content = Content(text) if isinstance(text, str) else text
24 main_style = f"{foreground} on {background}"
25 end_style = f"{background} on transparent r"
26 return Content.assemble(
27 (PILL_LEFT, end_style),
28 content.stylize(main_style),
29 (PILL_RIGHT, end_style),
30 )