-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.py
More file actions
70 lines (57 loc) · 1.94 KB
/
helpers.py
File metadata and controls
70 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Helper utilities for clean example output formatting.
"""
from typing import Any
from typing import Dict
from typing import Optional
class ExamplePrinter:
"""
Context manager for clean example outputs.
Usage:
with ExamplePrinter("My Example") as p:
p.section(1, 3, "First step")
p.success("It worked!")
"""
def __init__(self, title: str, footer: str = "Example completed!"):
self.title = title
self.footer_message = footer
def __enter__(self):
"""Print header on enter."""
print("\n" + "=" * 80)
print(self.title)
print("=" * 80)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
"""Print footer on exit."""
print("\n" + "=" * 80)
print(self.footer_message)
print("=" * 80)
return False
def section(self, number: int, total: int, title: str, description: str | None = None):
"""Print section header."""
print(f"\n[{number}/{total}] {title}")
print("-" * 80)
if description:
print(f"💡 {description}")
def success(self, message: str, details: dict[str, Any] | None = None):
"""Print success message with optional details."""
print(f"✅ {message}")
if details:
for key, value in details.items():
print(f" {key}: {value}")
def error(self, message: str):
"""Print error message."""
print(f"❌ {message}")
def warning(self, message: str):
"""Print warning message."""
print(f"⚠️ {message}")
def info(self, message: str, indent: int = 0):
"""Print info message."""
prefix = " " * indent
print(f"{prefix}{message}")
def list_items(self, items: list, title: str | None = None):
"""Print a list of items."""
if title:
print(f"\n{title}:")
for item in items:
print(f" - {item}")