Coverage for src / ezplog / types / protocols / printer_protocol.py: 100.00%

5 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-03 16:27 +0000

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

2# EZPL - Printer Protocol 

3# Project: ezpl 

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

5 

6""" 

7Printer Protocol for Ezpl logging framework. 

8 

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

13 

14from __future__ import annotations 

15 

16# /////////////////////////////////////////////////////////////// 

17# IMPORTS 

18# /////////////////////////////////////////////////////////////// 

19# Standard library imports 

20from contextlib import AbstractContextManager 

21from typing import Any, Protocol, runtime_checkable 

22 

23# Local imports 

24from ..enums import Pattern 

25 

26# /////////////////////////////////////////////////////////////// 

27# PROTOCOLS 

28# /////////////////////////////////////////////////////////////// 

29 

30 

31@runtime_checkable 

32class PrinterProtocol(Protocol): 

33 """ 

34 Protocol defining the interface for printer implementations. 

35 

36 All printer implementations must conform to this protocol to ensure 

37 consistent API and type safety. 

38 

39 **Required Methods:** 

40 - Logging methods: info(), debug(), success(), warning(), 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() 

45 

46 **Required Properties:** 

47 - wizard: Access to RichWizard instance for advanced features 

48 """ 

49 

50 # /////////////////////////////////////////////////////////////// 

51 # CORE LOGGING METHODS 

52 # /////////////////////////////////////////////////////////////// 

53 

54 def info(self, message: Any) -> None: 

55 """Log an info message.""" 

56 ... 

57 

58 def debug(self, message: Any) -> None: 

59 """Log a debug message.""" 

60 ... 

61 

62 def success(self, message: Any) -> None: 

63 """Log a success message.""" 

64 ... 

65 

66 def warning(self, message: Any) -> None: 

67 """Log a warning message.""" 

68 ... 

69 

70 def error(self, message: Any) -> None: 

71 """Log an error message.""" 

72 ... 

73 

74 def critical(self, message: Any) -> None: 

75 """Log a critical message.""" 

76 ... 

77 

78 # /////////////////////////////////////////////////////////////// 

79 # PATTERN METHODS 

80 # /////////////////////////////////////////////////////////////// 

81 

82 def tip(self, message: Any) -> None: 

83 """Display a tip message.""" 

84 ... 

85 

86 def system(self, message: Any) -> None: 

87 """Display a system message.""" 

88 ... 

89 

90 def install(self, message: Any) -> None: 

91 """Display an installation message.""" 

92 ... 

93 

94 def detect(self, message: Any) -> None: 

95 """Display a detection message.""" 

96 ... 

97 

98 def config(self, message: Any) -> None: 

99 """Display a configuration message.""" 

100 ... 

101 

102 def deps(self, message: Any) -> None: 

103 """Display a dependencies message.""" 

104 ... 

105 

106 # /////////////////////////////////////////////////////////////// 

107 # ENHANCED METHODS 

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

109 

110 def print_pattern( 

111 self, pattern: str | Pattern, message: Any, level: str = "INFO" 

112 ) -> None: 

113 """Display a message with pattern format.""" 

114 ... 

115 

116 def print_json( 

117 self, 

118 data: str | dict | list, 

119 title: str | None = None, 

120 indent: int | None = None, 

121 highlight: bool = True, 

122 ) -> None: 

123 """Display JSON data in formatted way.""" 

124 ... 

125 

126 # /////////////////////////////////////////////////////////////// 

127 # UTILITY METHODS 

128 # /////////////////////////////////////////////////////////////// 

129 

130 @property 

131 def level(self) -> str: 

132 """Get the current logging level.""" 

133 ... 

134 

135 def set_level(self, level: str) -> None: 

136 """Set the logging level.""" 

137 ... 

138 

139 def log(self, level: str, message: Any) -> None: 

140 """Log a message with specified level.""" 

141 ... 

142 

143 # /////////////////////////////////////////////////////////////// 

144 # INDENTATION METHODS 

145 # /////////////////////////////////////////////////////////////// 

146 

147 def add_indent(self) -> None: 

148 """Increase indentation level.""" 

149 ... 

150 

151 def del_indent(self) -> None: 

152 """Decrease indentation level.""" 

153 ... 

154 

155 def reset_indent(self) -> None: 

156 """Reset indentation to zero.""" 

157 ... 

158 

159 def manage_indent(self) -> AbstractContextManager[None]: 

160 """Context manager for temporary indentation.""" 

161 ... 

162 

163 # /////////////////////////////////////////////////////////////// 

164 # PROPERTIES 

165 # /////////////////////////////////////////////////////////////// 

166 

167 @property 

168 def wizard(self) -> Any: 

169 """Get RichWizard instance for advanced features.""" 

170 ... 

171 

172 

173# /////////////////////////////////////////////////////////////// 

174# PUBLIC API 

175# /////////////////////////////////////////////////////////////// 

176 

177__all__ = [ 

178 "PrinterProtocol", 

179]