-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
72 lines (53 loc) · 1.84 KB
/
Copy pathutils.py
File metadata and controls
72 lines (53 loc) · 1.84 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
71
72
from __future__ import annotations
from datetime import datetime
from typing import Iterable, List
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
console = Console()
def format_date(value: str | None) -> str:
if not value:
return "—"
try:
return datetime.strptime(value, "%Y-%m-%d").strftime("%b %d, %Y")
except ValueError:
return value
def validate_date(value: str | None) -> bool:
if not value:
return True
try:
datetime.strptime(value, "%Y-%m-%d")
return True
except ValueError:
return False
def priority_color(priority: str) -> str:
return {
"Low": "green",
"Medium": "cyan",
"High": "yellow",
}.get(priority.title(), "white")
def render_table(tasks: Iterable) -> None:
table = Table(title="Tasks", header_style="bold magenta")
table.add_column("ID", style="cyan", width=6)
table.add_column("Title", style="white")
table.add_column("Priority", style="magenta")
table.add_column("Category", style="blue")
table.add_column("Due", style="yellow")
table.add_column("Status", style="green")
for task in tasks:
status = "✓ completed" if task.completed else "✗ pending"
table.add_row(
str(task.id),
task.title,
f"[{priority_color(task.priority)}]{task.priority}[/{priority_color(task.priority)}]",
task.category,
format_date(task.due_date),
status,
)
console.print(table)
def show_error(message: str) -> None:
console.print(f"[bold red]Error:[/bold red] {message}")
def show_success(message: str) -> None:
console.print(f"[bold green]Success:[/bold green] {message}")
def show_info(message: str) -> None:
console.print(Panel.fit(message, border_style="blue"))