INNER CODE UNIT · Python
_ansi
i3T4AN/KADATH · kadath/cli.py:134
def _ansi(text: object, *codes: str) -> str:
return "".join(f"\033[{code}m" for code in codes) + str(text) + "\033[0m"
def _progress_bar(completed: int, total: int, width: int = 32) -> str:
filled = width if total <= 0 else max(0, min(width, round(width * completed / total)))
return _ansi("█" * filled, "38;5;84") + _ansi("░" * (width - filled), "38;5;245")
def _activity_summary(row: dict) -> str:
try:
payload = json.loads(row.get("payload_json") or "{}")
except (TypeError, json.JSONDecodeError):
payload = {}
summary = payload.get("summary") or payload.get("outcome") or row.get("kind", "activity")
return " ".join(str(summary).split())[:140]