This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Printr/printr/EllipsisPrintr/__init__.py

32 lines
795 B
Python
Raw Permalink Normal View History

2015-10-08 15:39:22 +01:00
from printr.utils import write
class EllipsisPrintr():
def __init__(self, string, max=3, erase_after=False):
self.string = string
self.max = max
self.count = -1
self.erase_after = erase_after
def update(self, commit=False):
self.clear()
ellipsis = "." * self.count
write(self.string + ellipsis, commit=commit)
if self.count >= self.max:
self.zero()
self.count += 1
def zero(self):
self.count = -1
def commit(self):
print()
def clear(self):
print(' ' * (len(self.string) + self.max), end='\r')
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
if self.erase_after:
self.clear()
self.commit()