-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading.py
47 lines (40 loc) · 1.33 KB
/
loading.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
from print_clearable import print, clear, clear_cache
def print_percent(percent, file=None):
if percent < 30:
color = "\033[31m"
elif percent < 50:
color = "\033[33m"
elif percent < 70:
color = "\033[93m"
elif percent < 95:
color = "\033[32m"
else:
color = "\033[92m"
import os
try:
width = os.get_terminal_size().columns - 1
except:
width = 1080
string_end = f" {percent} %"
string_start = "=" * int(percent / 100 * (width - len(string_end))) + ">"
string = " " * (width - (len(string_end) + len(string_start)))
string_bar = string_start + string
print(color, string_bar[:-1] + "|" + string_end, "\033[0m", sep="", end="\n", file=file, flush=True)
class Loading:
def __init__(self, valeur_initiale=0, file=None):
self._valeur = valeur_initiale
self.file = file
self.ligne_precedente_effacee = False
@property
def valeur(self):
return self._valeur
@valeur.setter
def valeur(self, nouvelle_valeur):
self._valeur = nouvelle_valeur
if self._valeur > 0 and not self.ligne_precedente_effacee:
clear(self.file)
print_percent(self._valeur, self.file)
if self._valeur >= 100:
clear_cache(self.file)
self._valeur = nouvelle_valeur
global LOADING