mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-07-31 04:00:12 -07:00
+xlib.console
This commit is contained in:
parent
bdd80e7cce
commit
2c61f5225b
2 changed files with 32 additions and 0 deletions
1
xlib/console/__init__.py
Normal file
1
xlib/console/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .console import progress_bar_iterator, progress_bar_print
|
31
xlib/console/console.py
Normal file
31
xlib/console/console.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from typing import Generator
|
||||||
|
|
||||||
|
_progress_symbols = "|/-\\"
|
||||||
|
|
||||||
|
def progress_bar_iterator(iterable, desc = '') -> Generator:
|
||||||
|
n_count = len(iterable)
|
||||||
|
|
||||||
|
progress_bar_print(0, n_count, desc)
|
||||||
|
for i, item in enumerate(iterable):
|
||||||
|
yield item
|
||||||
|
progress_bar_print(i + 1, n_count, desc)
|
||||||
|
|
||||||
|
def progress_bar_print(n, n_count, desc = ''):
|
||||||
|
str_max_len = 80
|
||||||
|
|
||||||
|
prefix_str = f'{desc} |'
|
||||||
|
prefix_str_len = len(prefix_str)
|
||||||
|
|
||||||
|
suffix_str = f'| {n}/{n_count}'
|
||||||
|
bar_len = str_max_len - (prefix_str_len+len(suffix_str))
|
||||||
|
|
||||||
|
|
||||||
|
bar_head = '#'*int( (n/n_count)*bar_len)
|
||||||
|
if n != n_count:
|
||||||
|
bar_head += _progress_symbols[n % len(_progress_symbols)]
|
||||||
|
bar_tail = '-'*( bar_len - len(bar_head) )
|
||||||
|
|
||||||
|
out = prefix_str + bar_head + bar_tail + suffix_str
|
||||||
|
print(out, end = '\r')
|
||||||
|
if n == n_count:
|
||||||
|
print()
|
Loading…
Add table
Add a link
Reference in a new issue