Coverage for src/ezplog/types/enums/patterns.py: 100.00%

25 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-16 19:04 +0000

1# /////////////////////////////////////////////////////////////// 

2# EZPL - Pattern definitions 

3# Project: ezpl 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7Pattern definitions for Ezpl logging framework. 

8 

9This module defines contextual patterns for enhanced console output with the format: 

10• PATTERN :: message 

11""" 

12 

13from __future__ import annotations 

14 

15# /////////////////////////////////////////////////////////////// 

16# IMPORTS 

17# /////////////////////////////////////////////////////////////// 

18# Standard library imports 

19from enum import Enum 

20 

21# /////////////////////////////////////////////////////////////// 

22# CLASSES 

23# /////////////////////////////////////////////////////////////// 

24 

25 

26class Pattern(Enum): 

27 """ 

28 Contextual patterns for console output. 

29 

30 Patterns provide semantic meaning beyond log levels, allowing for 

31 more expressive and contextual logging. 

32 """ 

33 

34 # Main patterns 

35 TRACE = "TRACE" 

36 SUCCESS = "SUCCESS" 

37 ERROR = "ERROR" 

38 WARN = "WARN" 

39 TIP = "TIP" 

40 DEBUG = "DEBUG" 

41 INFO = "INFO" 

42 

43 # System patterns 

44 SYSTEM = "SYSTEM" 

45 INSTALL = "INSTALL" 

46 DETECT = "DETECT" 

47 CONFIG = "CONFIG" 

48 DEPS = "DEPS" 

49 

50 

51# /////////////////////////////////////////////////////////////// 

52# VARIABLES 

53# /////////////////////////////////////////////////////////////// 

54 

55# Color mapping for patterns (Rich color names) 

56PATTERN_COLORS: dict[Pattern, str] = { 

57 # Main patterns 

58 Pattern.TRACE: "dim cyan", # ⚪ Trace (dimmed) 

59 Pattern.SUCCESS: "bright_green", # 🟢 Success 

60 Pattern.ERROR: "bright_red", # 🔴 Error 

61 Pattern.WARN: "bright_yellow", # 🟡 Warning 

62 Pattern.TIP: "bright_magenta", # 🟣 Tip 

63 Pattern.DEBUG: "dim white", # ⚪ Debug (dimmed) 

64 Pattern.INFO: "bright_blue", # 🔵 Info 

65 # System patterns 

66 Pattern.SYSTEM: "bright_blue", # 🔵 System operations 

67 Pattern.INSTALL: "bright_green", # 🟢 Installation 

68 Pattern.DETECT: "bright_blue", # 🔵 Detection/Analysis 

69 Pattern.CONFIG: "bright_green", # 🟢 Configuration 

70 Pattern.DEPS: "bright_cyan", # 🔵 Dependencies 

71} 

72 

73# /////////////////////////////////////////////////////////////// 

74# FUNCTIONS 

75# /////////////////////////////////////////////////////////////// 

76 

77 

78def get_pattern_color(pattern: Pattern) -> str: 

79 """ 

80 Get the Rich color style for a pattern. 

81 

82 Args: 

83 pattern: The pattern to get the color for 

84 

85 Returns: 

86 Rich color style string 

87 """ 

88 return PATTERN_COLORS.get(pattern, "white") 

89 

90 

91def get_pattern_color_by_name(pattern_name: str) -> str: 

92 """ 

93 Get the Rich color style for a pattern by name. 

94 

95 Args: 

96 pattern_name: The pattern name (case-insensitive) 

97 

98 Returns: 

99 Rich color style string 

100 """ 

101 try: 

102 pattern = Pattern[pattern_name.upper()] 

103 return get_pattern_color(pattern) 

104 except KeyError: 

105 return "white" 

106 

107 

108# /////////////////////////////////////////////////////////////// 

109# PUBLIC API 

110# /////////////////////////////////////////////////////////////// 

111 

112__all__ = [ 

113 "PATTERN_COLORS", 

114 "Pattern", 

115 "get_pattern_color", 

116 "get_pattern_color_by_name", 

117]