Coverage for src/lilbee/cli/tui/widgets/progress_cell.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""Progress bar renderables for the Task Center row. 

2 

3Returns plain strings so the enclosing Static's CSS colors the bar 

4per task state (active / done / failed / cancelled). Using Rich Text 

5here would hard-code a palette and fight the theme. 

6""" 

7 

8from __future__ import annotations 

9 

10from lilbee.cli.tui.messages import progress_bar_glyphs 

11 

12_BAR_WIDTH = 60 

13 

14 

15def progress_cell(percent: float, width: int = _BAR_WIDTH) -> str: 

16 """Render a 0-100 percent value as a bar + trailing %.""" 

17 fill, track = progress_bar_glyphs() 

18 pct = max(0.0, min(percent, 100.0)) 

19 filled = int(width * pct / 100) 

20 bar = fill * filled + track * (width - filled) 

21 return f"{bar} {pct:5.1f}%" 

22 

23 

24def indeterminate_cell(tick: int, width: int = _BAR_WIDTH) -> str: 

25 """Render an indeterminate pulse bar by sliding a 3-char window.""" 

26 fill, track = progress_bar_glyphs() 

27 pos = tick % (width + 3) 

28 cells = [track] * width 

29 for offset in (-1, 0, 1): 

30 i = pos + offset 

31 if 0 <= i < width: 

32 cells[i] = fill 

33 return "".join(cells) + " ···" 

34 

35 

36def frozen_indeterminate_cell(width: int = _BAR_WIDTH) -> str: 

37 """Render a non-animating indeterminate bar for terminal-state rows. 

38 

39 The bar is fully filled and trailing dots are dropped so the row no 

40 longer reads as 'work in progress' once the task has finished. The 

41 trailing percentage is omitted because an indeterminate task never 

42 had a real percentage to report. 

43 """ 

44 return progress_bar_glyphs()[0] * width