This commit is contained in:
Andras Schmelczer 2026-03-30 08:09:47 +01:00
commit 36d975545b
38 changed files with 2837 additions and 0 deletions

54
src/lib/progress.py Normal file
View file

@ -0,0 +1,54 @@
"""Simple terminal progress bar for e-ink frame."""
import sys
class ProgressBar:
"""Simple text-based progress bar."""
def __init__(self, total: int, desc: str = "", width: int = 30):
self.total = total
self.current = 0
self.desc = desc
self.width = width
self._last_percent = -1
def update(self, n: int = 1) -> None:
"""Update progress by n steps."""
self.current = min(self.current + n, self.total)
self._render()
def set(self, value: int) -> None:
"""Set progress to specific value."""
self.current = min(value, self.total)
self._render()
def _render(self) -> None:
if self.total == 0:
return
percent = int(100 * self.current / self.total)
if percent == self._last_percent:
return
self._last_percent = percent
filled = int(self.width * self.current / self.total)
bar = "█" * filled + "░" * (self.width - filled)
desc = f"{self.desc}: " if self.desc else ""
sys.stdout.write(f"\r{desc}|{bar}| {percent:3d}%")
sys.stdout.flush()
if self.current >= self.total:
sys.stdout.write("\n")
sys.stdout.flush()
def finish(self) -> None:
"""Complete the progress bar."""
self.current = self.total
self._render()
def print_status(msg: str) -> None:
"""Print a status message."""
print(f" {msg}")