Coverage for src / ezpl / types / enums / patterns.py: 100.00%
23 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-13 19:35 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-13 19:35 +0000
1# ///////////////////////////////////////////////////////////////
2# EZPL - Pattern definitions
3# Project: ezpl
4# ///////////////////////////////////////////////////////////////
6"""
7Pattern definitions for Ezpl logging framework.
9This module defines contextual patterns for enhanced console output with the format:
10• PATTERN :: message
11"""
13from __future__ import annotations
15# ///////////////////////////////////////////////////////////////
16# IMPORTS
17# ///////////////////////////////////////////////////////////////
18# Standard library imports
19from enum import Enum
21# ///////////////////////////////////////////////////////////////
22# CLASSES
23# ///////////////////////////////////////////////////////////////
26class Pattern(Enum):
27 """
28 Contextual patterns for console output.
30 Patterns provide semantic meaning beyond log levels, allowing for
31 more expressive and contextual logging.
32 """
34 # Main patterns
35 SUCCESS = "SUCCESS"
36 ERROR = "ERROR"
37 WARN = "WARN"
38 TIP = "TIP"
39 DEBUG = "DEBUG"
40 INFO = "INFO"
42 # System patterns
43 SYSTEM = "SYSTEM"
44 INSTALL = "INSTALL"
45 DETECT = "DETECT"
46 CONFIG = "CONFIG"
47 DEPS = "DEPS"
50# ///////////////////////////////////////////////////////////////
51# VARIABLES
52# ///////////////////////////////////////////////////////////////
54# Color mapping for patterns (Rich color names)
55PATTERN_COLORS: dict[Pattern, str] = {
56 # Main patterns
57 Pattern.SUCCESS: "bright_green", # 🟢 Success
58 Pattern.ERROR: "bright_red", # 🔴 Error
59 Pattern.WARN: "bright_yellow", # 🟡 Warning
60 Pattern.TIP: "bright_magenta", # 🟣 Tip
61 Pattern.DEBUG: "dim white", # ⚪ Debug (dimmed)
62 Pattern.INFO: "bright_blue", # 🔵 Info
63 # System patterns
64 Pattern.SYSTEM: "bright_blue", # 🔵 System operations
65 Pattern.INSTALL: "bright_green", # 🟢 Installation
66 Pattern.DETECT: "bright_blue", # 🔵 Detection/Analysis
67 Pattern.CONFIG: "bright_green", # 🟢 Configuration
68 Pattern.DEPS: "bright_cyan", # 🔵 Dependencies
69}
71# ///////////////////////////////////////////////////////////////
72# FUNCTIONS
73# ///////////////////////////////////////////////////////////////
76def get_pattern_color(pattern: Pattern) -> str:
77 """
78 Get the Rich color style for a pattern.
80 Args:
81 pattern: The pattern to get the color for
83 Returns:
84 Rich color style string
85 """
86 return PATTERN_COLORS.get(pattern, "white")
89def get_pattern_color_by_name(pattern_name: str) -> str:
90 """
91 Get the Rich color style for a pattern by name.
93 Args:
94 pattern_name: The pattern name (case-insensitive)
96 Returns:
97 Rich color style string
98 """
99 try:
100 pattern = Pattern[pattern_name.upper()]
101 return get_pattern_color(pattern)
102 except KeyError:
103 return "white"