ConsoleLib 1.3.1__tar.gz → 1.3.3__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.
- {consolelib-1.3.1 → consolelib-1.3.3}/ConsoleLib/__init__.py +198 -2
- {consolelib-1.3.1 → consolelib-1.3.3}/ConsoleLib.egg-info/PKG-INFO +1 -1
- {consolelib-1.3.1 → consolelib-1.3.3}/PKG-INFO +1 -1
- {consolelib-1.3.1 → consolelib-1.3.3}/pyproject.toml +1 -1
- {consolelib-1.3.1 → consolelib-1.3.3}/ConsoleLib.egg-info/SOURCES.txt +0 -0
- {consolelib-1.3.1 → consolelib-1.3.3}/ConsoleLib.egg-info/dependency_links.txt +0 -0
- {consolelib-1.3.1 → consolelib-1.3.3}/ConsoleLib.egg-info/top_level.txt +0 -0
- {consolelib-1.3.1 → consolelib-1.3.3}/README.md +0 -0
- {consolelib-1.3.1 → consolelib-1.3.3}/setup.cfg +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
ConsoleLib - The best Console
|
|
2
|
+
ConsoleLib - The best Console Library of the Python.
|
|
3
3
|
By: Suleiman
|
|
4
4
|
Copyright © Suleiman 2026
|
|
5
5
|
All rights are reserved.
|
|
@@ -10,7 +10,203 @@ 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 Colors:
|
|
15
|
+
RESET = "\033[0m"
|
|
16
|
+
BOLD = "\033[1m"
|
|
17
|
+
DIM = "\033[2m"
|
|
18
|
+
ITALIC = "\033[3m"
|
|
19
|
+
UNDERLINE = "\033[4m"
|
|
20
|
+
BLINK = "\033[5m"
|
|
21
|
+
REVERSE = "\033[7m"
|
|
22
|
+
HIDDEN = "\033[8m"
|
|
23
|
+
STRIKE = "\033[9m"
|
|
24
|
+
BLACK = "\033[30m"
|
|
25
|
+
RED = "\033[31m"
|
|
26
|
+
GREEN = "\033[32m"
|
|
27
|
+
YELLOW = "\033[33m"
|
|
28
|
+
BLUE = "\033[34m"
|
|
29
|
+
MAGENTA = "\033[35m"
|
|
30
|
+
CYAN = "\033[36m"
|
|
31
|
+
WHITE = "\033[37m"
|
|
32
|
+
BRIGHT_BLACK = "\033[90m"
|
|
33
|
+
BRIGHT_RED = "\033[91m"
|
|
34
|
+
BRIGHT_GREEN = "\033[92m"
|
|
35
|
+
BRIGHT_YELLOW = "\033[93m"
|
|
36
|
+
BRIGHT_BLUE = "\033[94m"
|
|
37
|
+
BRIGHT_MAGENTA = "\033[95m"
|
|
38
|
+
BRIGHT_CYAN = "\033[96m"
|
|
39
|
+
BRIGHT_WHITE = "\033[97m"
|
|
40
|
+
BG_BLACK = "\033[40m"
|
|
41
|
+
BG_RED = "\033[41m"
|
|
42
|
+
BG_GREEN = "\033[42m"
|
|
43
|
+
BG_YELLOW = "\033[43m"
|
|
44
|
+
BG_BLUE = "\033[44m"
|
|
45
|
+
BG_MAGENTA = "\033[45m"
|
|
46
|
+
BG_CYAN = "\033[46m"
|
|
47
|
+
BG_WHITE = "\033[47m"
|
|
48
|
+
BG_BRIGHT_BLACK = "\033[100m"
|
|
49
|
+
BG_BRIGHT_RED = "\033[101m"
|
|
50
|
+
BG_BRIGHT_GREEN = "\033[102m"
|
|
51
|
+
BG_BRIGHT_YELLOW = "\033[103m"
|
|
52
|
+
BG_BRIGHT_BLUE = "\033[104m"
|
|
53
|
+
BG_BRIGHT_MAGENTA = "\033[105m"
|
|
54
|
+
BG_BRIGHT_CYAN = "\033[106m"
|
|
55
|
+
BG_BRIGHT_WHITE = "\033[107m"
|
|
56
|
+
@staticmethod
|
|
57
|
+
def rgb(r, g, b):
|
|
58
|
+
return f"\033[38;2;{r};{g};{b}m"
|
|
59
|
+
@staticmethod
|
|
60
|
+
def bg_rgb(r, g, b):
|
|
61
|
+
return f"\033[48;2;{r};{g};{b}m"
|
|
62
|
+
@staticmethod
|
|
63
|
+
def colorize(text, color, reset=True):
|
|
64
|
+
reset_code = Colors.RESET if reset else ""
|
|
65
|
+
return f"{color}{text}{reset_code}"
|
|
66
|
+
class Animate:
|
|
67
|
+
def clear_screen():
|
|
68
|
+
os.system('cls' if os.name == 'nt' else 'clear')
|
|
69
|
+
class ProgressBar:
|
|
70
|
+
def __init__(
|
|
71
|
+
self,
|
|
72
|
+
total: int,
|
|
73
|
+
prefix: str = "Progress:",
|
|
74
|
+
suffix: str = "Complete",
|
|
75
|
+
length: int = 40,
|
|
76
|
+
fill: str = "█",
|
|
77
|
+
empty: str = "░",
|
|
78
|
+
show_percent: bool = True,
|
|
79
|
+
show_counter: bool = True,
|
|
80
|
+
auto_clear: bool = False,
|
|
81
|
+
clear_delay: float = 0.5,
|
|
82
|
+
):
|
|
83
|
+
self.total = total
|
|
84
|
+
self.prefix = prefix
|
|
85
|
+
self.suffix = suffix
|
|
86
|
+
self.length = length
|
|
87
|
+
self.fill = fill
|
|
88
|
+
self.empty = empty
|
|
89
|
+
self.show_percent = show_percent
|
|
90
|
+
self.show_counter = show_counter
|
|
91
|
+
self.auto_clear = auto_clear
|
|
92
|
+
self.clear_delay = clear_delay
|
|
93
|
+
self.current = 0
|
|
94
|
+
self._lock = threading.Lock()
|
|
95
|
+
self._finished = False
|
|
96
|
+
self._cleared = False
|
|
97
|
+
|
|
98
|
+
def update(self, increment: int = 1) -> None:
|
|
99
|
+
with self._lock:
|
|
100
|
+
if self._finished:
|
|
101
|
+
return
|
|
102
|
+
self.current = min(self.current + increment, self.total)
|
|
103
|
+
self._print_bar()
|
|
104
|
+
|
|
105
|
+
if self.current >= self.total:
|
|
106
|
+
self._finished = True
|
|
107
|
+
print()
|
|
108
|
+
|
|
109
|
+
def set(self, value: int) -> None:
|
|
110
|
+
with self._lock:
|
|
111
|
+
if self._finished:
|
|
112
|
+
return
|
|
113
|
+
self.current = max(0, min(value, self.total))
|
|
114
|
+
self._print_bar()
|
|
115
|
+
if self.current >= self.total:
|
|
116
|
+
self._finished = True
|
|
117
|
+
print()
|
|
118
|
+
def _print_bar(self) -> None:
|
|
119
|
+
percent = self.current / self.total
|
|
120
|
+
filled_len = int(self.length * percent)
|
|
121
|
+
bar = self.fill * filled_len + self.empty * (self.length - filled_len)
|
|
122
|
+
parts = [self.prefix, f"[{bar}]"]
|
|
123
|
+
if self.show_percent:
|
|
124
|
+
parts.append(f"{percent:.1%}")
|
|
125
|
+
if self.show_counter:
|
|
126
|
+
parts.append(f"({self.current}/{self.total})")
|
|
127
|
+
if self.suffix:
|
|
128
|
+
parts.append(self.suffix)
|
|
129
|
+
line = " ".join(parts)
|
|
130
|
+
sys.stdout.write("\r" + line)
|
|
131
|
+
sys.stdout.flush()
|
|
132
|
+
|
|
133
|
+
def __enter__(self):
|
|
134
|
+
if self.auto_clear and not self._cleared:
|
|
135
|
+
clear_screen()
|
|
136
|
+
self._cleared = True
|
|
137
|
+
if self.clear_delay > 0:
|
|
138
|
+
time.sleep(self.clear_delay)
|
|
139
|
+
return self
|
|
140
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
141
|
+
if not self._finished:
|
|
142
|
+
self._print_bar()
|
|
143
|
+
print()
|
|
144
|
+
def iterate(self, iterable: Iterator) -> Iterator:
|
|
145
|
+
for i, item in enumerate(iterable):
|
|
146
|
+
yield item
|
|
147
|
+
self.update(1)
|
|
148
|
+
def animate_print(
|
|
149
|
+
text: str,
|
|
150
|
+
delay: float = 0.05,
|
|
151
|
+
end: str = "\n",
|
|
152
|
+
flush: bool = True,
|
|
153
|
+
backspace_effect: bool = False,
|
|
154
|
+
) -> None:
|
|
155
|
+
if backspace_effect:
|
|
156
|
+
for ch in text:
|
|
157
|
+
sys.stdout.write(ch)
|
|
158
|
+
sys.stdout.flush()
|
|
159
|
+
time.sleep(delay)
|
|
160
|
+
time.sleep(0.2)
|
|
161
|
+
for _ in text:
|
|
162
|
+
sys.stdout.write("\b \b")
|
|
163
|
+
sys.stdout.flush()
|
|
164
|
+
time.sleep(delay / 2)
|
|
165
|
+
for ch in text:
|
|
166
|
+
sys.stdout.write(ch)
|
|
167
|
+
sys.stdout.flush()
|
|
168
|
+
time.sleep(delay)
|
|
169
|
+
sys.stdout.write(end)
|
|
170
|
+
sys.stdout.flush()
|
|
171
|
+
else:
|
|
172
|
+
for ch in text:
|
|
173
|
+
sys.stdout.write(ch)
|
|
174
|
+
if flush:
|
|
175
|
+
sys.stdout.flush()
|
|
176
|
+
time.sleep(delay)
|
|
177
|
+
sys.stdout.write(end)
|
|
178
|
+
if flush:
|
|
179
|
+
sys.stdout.flush()
|
|
180
|
+
def spinning_cursor(
|
|
181
|
+
message: str = "Loading",
|
|
182
|
+
duration: float = 3.0,
|
|
183
|
+
delay: float = 0.1,
|
|
184
|
+
frames: Optional[List[str]] = None,
|
|
185
|
+
clear_before: bool = False,
|
|
186
|
+
) -> None:
|
|
187
|
+
if clear_before:
|
|
188
|
+
clear_screen()
|
|
189
|
+
if frames is None:
|
|
190
|
+
frames = ["|", "/", "-", r"\\"]
|
|
191
|
+
end_time = time.time() + duration
|
|
192
|
+
idx = 0
|
|
193
|
+
while time.time() < end_time:
|
|
194
|
+
frame = frames[idx % len(frames)]
|
|
195
|
+
sys.stdout.write(f"\r{message} {frame} ")
|
|
196
|
+
sys.stdout.flush()
|
|
197
|
+
time.sleep(delay)
|
|
198
|
+
idx += 1
|
|
199
|
+
sys.stdout.write("\r" + " " * (len(message) + 3) + "\r")
|
|
200
|
+
sys.stdout.flush()
|
|
201
|
+
def countdown(seconds: int, message: str = "Countdown", clear_before: bool = False) -> None:
|
|
202
|
+
if clear_before:
|
|
203
|
+
clear_screen()
|
|
204
|
+
for remaining in range(seconds, 0, -1):
|
|
205
|
+
sys.stdout.write(f"\r{message}: {remaining:2d} seconds remaining ")
|
|
206
|
+
sys.stdout.flush()
|
|
207
|
+
time.sleep(1)
|
|
208
|
+
sys.stdout.write(f"\r{message}: 0 seconds remaining! Done!\n")
|
|
209
|
+
sys.stdout.flush()
|
|
14
210
|
class Render:
|
|
15
211
|
@staticmethod
|
|
16
212
|
def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ConsoleLib"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.3"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|