Add static method padding()
This commit is contained in:
parent
546391cb9c
commit
3ec5cf9973
@ -899,6 +899,26 @@ class Escpos(object, metaclass=ABCMeta):
|
|||||||
col_count = self.profile.get_columns(font) if columns is None else columns
|
col_count = self.profile.get_columns(font) if columns is None else columns
|
||||||
self.text(textwrap.fill(txt, col_count))
|
self.text(textwrap.fill(txt, col_count))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def padding(
|
||||||
|
text: str,
|
||||||
|
width: int,
|
||||||
|
align: Alignment = "center",
|
||||||
|
) -> str:
|
||||||
|
"""Add fill space to meet the width.
|
||||||
|
|
||||||
|
The align parameter sets the alignment of the text in space.
|
||||||
|
"""
|
||||||
|
align = align.lower()
|
||||||
|
if align == "center":
|
||||||
|
text = f"{text:^{width}}"
|
||||||
|
elif align == "left":
|
||||||
|
text = f"{text:<{width}}"
|
||||||
|
elif align == "right":
|
||||||
|
text = f"{text:>{width}}"
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
def set(
|
def set(
|
||||||
self,
|
self,
|
||||||
align: Optional[str] = None,
|
align: Optional[str] = None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user