Add static method _repeat_last()

This commit is contained in:
belono 2024-05-30 18:00:44 +02:00
parent 0e794f4bf0
commit 673504e331

View File

@ -929,6 +929,17 @@ class Escpos(object, metaclass=ABCMeta):
max_len = width - ph_len
return f"{text[:max_len]}{placeholder}" if len(text) > width else text
@staticmethod
def _repeat_last(iterable, max_iterations: int = 1000):
"""Iterate over the items of a list repeating the last one until max_iterations."""
i = 0
while i < max_iterations:
try:
yield iterable[i]
except IndexError:
yield iterable[-1]
i += 1
def set(
self,
align: Optional[str] = None,