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

1"""Text emphasis formatting utilities. 

2 

3Simple text formatting for terminal output. 

4""" 

5 

6from enum import Enum 

7 

8 

9class VisualEmphasis(Enum): 

10 """Visual emphasis levels.""" 

11 

12 NONE = "none" 

13 SUBTLE = "subtle" 

14 MODERATE = "moderate" 

15 STRONG = "strong" 

16 CRITICAL = "critical" 

17 

18 

19def bold(text: str) -> str: 

20 """Make text bold (terminal).""" 

21 return f"\033[1m{text}\033[0m" 

22 

23 

24def italic(text: str) -> str: 

25 """Make text italic (terminal).""" 

26 return f"\033[3m{text}\033[0m" 

27 

28 

29def underline(text: str) -> str: 

30 """Underline text (terminal).""" 

31 return f"\033[4m{text}\033[0m" 

32 

33 

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" 

47 

48 

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")) 

59 

60 

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) 

71 

72 

73__all__ = [ 

74 "VisualEmphasis", 

75 "bold", 

76 "color", 

77 "format_callout_box", 

78 "format_severity", 

79 "italic", 

80 "underline", 

81]