Display a plan credit line with progress bar.
(plan_credits: dict)
| 19 | |
| 20 | |
| 21 | def _display_credit_line(plan_credits: dict) -> None: |
| 22 | """Display a plan credit line with progress bar.""" |
| 23 | plan_type = plan_credits["type"] |
| 24 | remaining = plan_credits["remaining"] |
| 25 | total = plan_credits["total"] |
| 26 | period_end = plan_credits["period_end"] |
| 27 | |
| 28 | # Parse ISO-8601 timestamp and format as "Jun 1, 2026" |
| 29 | # Handle both with and without timezone info |
| 30 | dt_str = period_end.replace("Z", "+00:00") |
| 31 | dt = datetime.fromisoformat(dt_str) |
| 32 | # If naive datetime, assume UTC |
| 33 | if dt.tzinfo is None: |
| 34 | dt = dt.replace(tzinfo=timezone.utc) |
| 35 | formatted_date = dt.strftime("%b %-d, %Y") |
| 36 | |
| 37 | # Check if expired |
| 38 | now = datetime.now(timezone.utc) |
| 39 | is_expired = dt < now |
| 40 | |
| 41 | # Create progress bar (30 chars wide) |
| 42 | bar = _create_progress_bar(remaining, total, width=30) |
| 43 | |
| 44 | # Format plan type label |
| 45 | plan_label = "Free trial" if plan_type == "free" else plan_type.upper() + " plan" |
| 46 | |
| 47 | if is_expired: |
| 48 | console.print(f" {plan_label:10} {bar} expired {formatted_date}") |
| 49 | else: |
| 50 | console.print(f" {plan_label:10} {bar} {remaining:2} of {total} remaining expires {formatted_date}") |
| 51 | |
| 52 | |
| 53 | def _display_bucket_credit_line(bucket: dict, label: str) -> None: |