from escpos.printer import Dummy class ConsolePrinter(Dummy): def __init__(self, width=42): super().__init__() self.width = width # characters per line self.align = 'left' def set(self, align='left', font='a', **kwargs): self.align = align def text(self, txt): lines = txt.splitlines() for line in lines: formatted = self._format_line(line) print(formatted) def _format_line(self, line: str) -> str: # Apply alignment if self.align == 'center': return line.center(self.width) elif self.align == 'right': return line.rjust(self.width) else: return line.ljust(self.width) def qr(self, content, center=False, **kwargs): self.set(align='center' if center else 'left', **kwargs) print(self._format_line("+------------------------------------+")) print(self._format_line("+ ##### ##### +")) print(self._format_line("+ ## ## ## ## +")) print(self._format_line("+ ##### ##### +")) print(self._format_line("+ +")) print(self._format_line("+ +")) print(self._format_line("+ +")) print(self._format_line("+ +")) print(self._format_line("+ +")) print(self._format_line("+ +")) print(self._format_line("+ ##### +")) print(self._format_line("+ ## ## +")) print(self._format_line("+ ##### +")) print(self._format_line("+------------------------------------+")) def cut(self, mode='FULL', feed=True): pass def is_online(self): return True