Coverage for src / ezpl / types / protocols / printer_protocol.py: 100.00%
4 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 - Printer Protocol
3# Project: ezpl
4# ///////////////////////////////////////////////////////////////
6"""
7Printer Protocol for Ezpl logging framework.
9This module defines the Protocol (abstract interface) that all printer
10implementations must follow. It provides type checking and ensures
11consistent API across different printer implementations.
12"""
14from __future__ import annotations
16# ///////////////////////////////////////////////////////////////
17# IMPORTS
18# ///////////////////////////////////////////////////////////////
19# Standard library imports
20from contextlib import AbstractContextManager
21from typing import Any, Protocol, runtime_checkable
23# Local imports
24from ..enums import Pattern
26# ///////////////////////////////////////////////////////////////
27# PROTOCOLS
28# ///////////////////////////////////////////////////////////////
31@runtime_checkable
32class PrinterProtocol(Protocol):
33 """
34 Protocol defining the interface for printer implementations.
36 All printer implementations must conform to this protocol to ensure
37 consistent API and type safety.
39 **Required Methods:**
40 - Logging methods: info(), debug(), success(), warning(), warn(), error(), critical()
41 - Pattern methods: tip(), system(), install(), detect(), config(), deps()
42 - Enhanced methods: print_pattern(), print_json()
43 - Utility methods: set_level(), log()
44 - Indentation methods: add_indent(), del_indent(), reset_indent(), manage_indent()
46 **Required Properties:**
47 - wizard: Access to RichWizard instance for advanced features
48 """
50 # ///////////////////////////////////////////////////////////////
51 # CORE LOGGING METHODS
52 # ///////////////////////////////////////////////////////////////
54 def info(self, message: Any) -> None:
55 """Log an info message."""
56 ...
58 def debug(self, message: Any) -> None:
59 """Log a debug message."""
60 ...
62 def success(self, message: Any) -> None:
63 """Log a success message."""
64 ...
66 def warning(self, message: Any) -> None:
67 """Log a warning message."""
68 ...
70 def warn(self, message: Any) -> None:
71 """Alias for warning(). Log a warning message."""
72 ...
74 def error(self, message: Any) -> None:
75 """Log an error message."""
76 ...
78 def critical(self, message: Any) -> None:
79 """Log a critical message."""
80 ...
82 # ///////////////////////////////////////////////////////////////
83 # PATTERN METHODS
84 # ///////////////////////////////////////////////////////////////
86 def tip(self, message: Any) -> None:
87 """Display a tip message."""
88 ...
90 def system(self, message: Any) -> None:
91 """Display a system message."""
92 ...
94 def install(self, message: Any) -> None:
95 """Display an installation message."""
96 ...
98 def detect(self, message: Any) -> None:
99 """Display a detection message."""
100 ...
102 def config(self, message: Any) -> None:
103 """Display a configuration message."""
104 ...
106 def deps(self, message: Any) -> None:
107 """Display a dependencies message."""
108 ...
110 # ///////////////////////////////////////////////////////////////
111 # ENHANCED METHODS
112 # ///////////////////////////////////////////////////////////////
114 def print_pattern(
115 self, pattern: str | Pattern, message: Any, level: str = "INFO"
116 ) -> None:
117 """Display a message with pattern format."""
118 ...
120 def print_json(
121 self,
122 data: str | dict | list,
123 title: str | None = None,
124 indent: int | None = None,
125 highlight: bool = True,
126 ) -> None:
127 """Display JSON data in formatted way."""
128 ...
130 # ///////////////////////////////////////////////////////////////
131 # UTILITY METHODS
132 # ///////////////////////////////////////////////////////////////
134 @property
135 def level(self) -> str:
136 """Get the current logging level."""
137 ...
139 def set_level(self, level: str) -> None:
140 """Set the logging level."""
141 ...
143 def log(self, level: str, message: Any) -> None:
144 """Log a message with specified level."""
145 ...
147 # ///////////////////////////////////////////////////////////////
148 # INDENTATION METHODS
149 # ///////////////////////////////////////////////////////////////
151 def add_indent(self) -> None:
152 """Increase indentation level."""
153 ...
155 def del_indent(self) -> None:
156 """Decrease indentation level."""
157 ...
159 def reset_indent(self) -> None:
160 """Reset indentation to zero."""
161 ...
163 def manage_indent(self) -> AbstractContextManager[None]:
164 """Context manager for temporary indentation."""
165 ...
167 # ///////////////////////////////////////////////////////////////
168 # PROPERTIES
169 # ///////////////////////////////////////////////////////////////
171 @property
172 def wizard(self) -> Any:
173 """Get RichWizard instance for advanced features."""
174 ...