Coverage for src / tracekit / reporting / formatting / emphasis.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 23:04 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 23:04 +0000
1"""Text emphasis formatting utilities.
3Simple text formatting for terminal output.
4"""
6from enum import Enum
9class VisualEmphasis(Enum):
10 """Visual emphasis levels."""
12 NONE = "none"
13 SUBTLE = "subtle"
14 MODERATE = "moderate"
15 STRONG = "strong"
16 CRITICAL = "critical"
19def bold(text: str) -> str:
20 """Make text bold (terminal)."""
21 return f"\033[1m{text}\033[0m"
24def italic(text: str) -> str:
25 """Make text italic (terminal)."""
26 return f"\033[3m{text}\033[0m"
29def underline(text: str) -> str:
30 """Underline text (terminal)."""
31 return f"\033[4m{text}\033[0m"
34def color(text: str, color_code: str) -> str:
35 """Color text (terminal)."""
36 colors = {
37 "red": "31",
38 "green": "32",
39 "yellow": "33",
40 "blue": "34",
41 "magenta": "35",
42 "cyan": "36",
43 "white": "37",
44 }
45 code = colors.get(color_code.lower(), "37")
46 return f"\033[{code}m{text}\033[0m"
49def format_severity(text: str, severity: str) -> str:
50 """Format text based on severity level."""
51 severity_colors = {
52 "critical": "red",
53 "error": "red",
54 "warning": "yellow",
55 "info": "blue",
56 "success": "green",
57 }
58 return color(text, severity_colors.get(severity.lower(), "white"))
61def format_callout_box(title: str, content: str, severity: str = "info") -> str:
62 """Format a callout box."""
63 lines = [
64 "=" * 60,
65 format_severity(f" {title.upper()} ", severity),
66 "-" * 60,
67 content,
68 "=" * 60,
69 ]
70 return "\n".join(lines)
73__all__ = [
74 "VisualEmphasis",
75 "bold",
76 "color",
77 "format_callout_box",
78 "format_severity",
79 "italic",
80 "underline",
81]