ConsoleLib 1.3.1__tar.gz → 1.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,151 @@ import time
10
10
  import subprocess as CMD
11
11
  import math
12
12
  import random
13
-
13
+ from typing import Optional, Iterator, List
14
+ class Animate:
15
+ def clear_screen():
16
+ os.system('cls' if os.name == 'nt' else 'clear')
17
+ class ProgressBar:
18
+ def __init__(
19
+ self,
20
+ total: int,
21
+ prefix: str = "Progress:",
22
+ suffix: str = "Complete",
23
+ length: int = 40,
24
+ fill: str = "█",
25
+ empty: str = "░",
26
+ show_percent: bool = True,
27
+ show_counter: bool = True,
28
+ auto_clear: bool = False,
29
+ clear_delay: float = 0.5,
30
+ ):
31
+ self.total = total
32
+ self.prefix = prefix
33
+ self.suffix = suffix
34
+ self.length = length
35
+ self.fill = fill
36
+ self.empty = empty
37
+ self.show_percent = show_percent
38
+ self.show_counter = show_counter
39
+ self.auto_clear = auto_clear
40
+ self.clear_delay = clear_delay
41
+ self.current = 0
42
+ self._lock = threading.Lock()
43
+ self._finished = False
44
+ self._cleared = False
45
+
46
+ def update(self, increment: int = 1) -> None:
47
+ with self._lock:
48
+ if self._finished:
49
+ return
50
+ self.current = min(self.current + increment, self.total)
51
+ self._print_bar()
52
+
53
+ if self.current >= self.total:
54
+ self._finished = True
55
+ print()
56
+
57
+ def set(self, value: int) -> None:
58
+ with self._lock:
59
+ if self._finished:
60
+ return
61
+ self.current = max(0, min(value, self.total))
62
+ self._print_bar()
63
+ if self.current >= self.total:
64
+ self._finished = True
65
+ print()
66
+ def _print_bar(self) -> None:
67
+ percent = self.current / self.total
68
+ filled_len = int(self.length * percent)
69
+ bar = self.fill * filled_len + self.empty * (self.length - filled_len)
70
+ parts = [self.prefix, f"[{bar}]"]
71
+ if self.show_percent:
72
+ parts.append(f"{percent:.1%}")
73
+ if self.show_counter:
74
+ parts.append(f"({self.current}/{self.total})")
75
+ if self.suffix:
76
+ parts.append(self.suffix)
77
+ line = " ".join(parts)
78
+ sys.stdout.write("\r" + line)
79
+ sys.stdout.flush()
80
+
81
+ def __enter__(self):
82
+ if self.auto_clear and not self._cleared:
83
+ clear_screen()
84
+ self._cleared = True
85
+ if self.clear_delay > 0:
86
+ time.sleep(self.clear_delay)
87
+ return self
88
+ def __exit__(self, exc_type, exc_val, exc_tb):
89
+ if not self._finished:
90
+ self._print_bar()
91
+ print()
92
+ def iterate(self, iterable: Iterator) -> Iterator:
93
+ for i, item in enumerate(iterable):
94
+ yield item
95
+ self.update(1)
96
+ def animate_print(
97
+ text: str,
98
+ delay: float = 0.05,
99
+ end: str = "\n",
100
+ flush: bool = True,
101
+ backspace_effect: bool = False,
102
+ ) -> None:
103
+ if backspace_effect:
104
+ for ch in text:
105
+ sys.stdout.write(ch)
106
+ sys.stdout.flush()
107
+ time.sleep(delay)
108
+ time.sleep(0.2)
109
+ for _ in text:
110
+ sys.stdout.write("\b \b")
111
+ sys.stdout.flush()
112
+ time.sleep(delay / 2)
113
+ for ch in text:
114
+ sys.stdout.write(ch)
115
+ sys.stdout.flush()
116
+ time.sleep(delay)
117
+ sys.stdout.write(end)
118
+ sys.stdout.flush()
119
+ else:
120
+ for ch in text:
121
+ sys.stdout.write(ch)
122
+ if flush:
123
+ sys.stdout.flush()
124
+ time.sleep(delay)
125
+ sys.stdout.write(end)
126
+ if flush:
127
+ sys.stdout.flush()
128
+ def spinning_cursor(
129
+ message: str = "Loading",
130
+ duration: float = 3.0,
131
+ delay: float = 0.1,
132
+ frames: Optional[List[str]] = None,
133
+ clear_before: bool = False,
134
+ ) -> None:
135
+ if clear_before:
136
+ clear_screen()
137
+ if frames is None:
138
+ frames = ["|", "/", "-", r"\\"]
139
+ end_time = time.time() + duration
140
+ idx = 0
141
+ while time.time() < end_time:
142
+ frame = frames[idx % len(frames)]
143
+ sys.stdout.write(f"\r{message} {frame} ")
144
+ sys.stdout.flush()
145
+ time.sleep(delay)
146
+ idx += 1
147
+ sys.stdout.write("\r" + " " * (len(message) + 3) + "\r")
148
+ sys.stdout.flush()
149
+ def countdown(seconds: int, message: str = "Countdown", clear_before: bool = False) -> None:
150
+ if clear_before:
151
+ clear_screen()
152
+ for remaining in range(seconds, 0, -1):
153
+ sys.stdout.write(f"\r{message}: {remaining:2d} seconds remaining ")
154
+ sys.stdout.flush()
155
+ time.sleep(1)
156
+ sys.stdout.write(f"\r{message}: 0 seconds remaining! Done!\n")
157
+ sys.stdout.flush()
14
158
  class Render:
15
159
  @staticmethod
16
160
  def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleLib
3
- Version: 1.3.1
3
+ Version: 1.3.2
4
4
  Summary: The library for easy and best control on the Console.
5
5
  Author-email: Suleiman <steal.apet@mail.ru>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ConsoleLib
3
- Version: 1.3.1
3
+ Version: 1.3.2
4
4
  Summary: The library for easy and best control on the Console.
5
5
  Author-email: Suleiman <steal.apet@mail.ru>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ConsoleLib"
7
- version = "1.3.1"
7
+ version = "1.3.2"
8
8
  description = "The library for easy and best control on the Console."
9
9
  authors = [{name = "Suleiman", email = "steal.apet@mail.ru"}]
10
10
  readme = "README.md"
File without changes
File without changes