This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
console_printing.py
61 lines (48 loc) · 1.66 KB
/
console_printing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import shutil
import sys
term_size = shutil.get_terminal_size()[0] - 1
text = {
"RED--": u"\u001b[31m",
"GREEN": u"\u001b[32m",
"NORM-": u"\u001b[0m",
"CYAN-": u"\u001b[36m",
"BLUE-": u"\u001b[34m"
}
def remove_lines(num_lines):
for i in range(num_lines):
remove_line()
def remove_line():
os.system('')
sys.stdout.write("\033[F")
print(" " * term_size)
os.system('')
sys.stdout.write("\033[F")
# Print iterations progress
def print_progress_bar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█'):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
fill - Optional : bar fill character (Str)
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
"""
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
filled_length = int(length * iteration // total)
bar = fill * filled_length + '-' * (length - filled_length)
print(ctr(f'{prefix} |{bar}| '))
print(ctr(f'{percent}% {suffix}'))
# Print New Line on Complete
if iteration == total:
print()
def ctrs(string, string2):
return string.center(term_size, ' ').replace(string, string2)
def ctr(string):
return string.center(term_size, ' ')
def ral(string):
return string.rjust(term_size, ' ')