Add static method _repeat_last()
This commit is contained in:
parent
0e794f4bf0
commit
673504e331
@ -929,6 +929,17 @@ class Escpos(object, metaclass=ABCMeta):
|
|||||||
max_len = width - ph_len
|
max_len = width - ph_len
|
||||||
return f"{text[:max_len]}{placeholder}" if len(text) > width else text
|
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(
|
def set(
|
||||||
self,
|
self,
|
||||||
align: Optional[str] = None,
|
align: Optional[str] = None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user