ConsoleLib 1.2.1__tar.gz → 1.2.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.
- consolelib-1.2.2/ConsoleLib/__init__.py +223 -0
- {consolelib-1.2.1 → consolelib-1.2.2}/ConsoleLib.egg-info/PKG-INFO +1 -1
- {consolelib-1.2.1 → consolelib-1.2.2}/PKG-INFO +1 -1
- {consolelib-1.2.1 → consolelib-1.2.2}/pyproject.toml +1 -1
- consolelib-1.2.1/ConsoleLib/__init__.py +0 -88
- {consolelib-1.2.1 → consolelib-1.2.2}/ConsoleLib.egg-info/SOURCES.txt +0 -0
- {consolelib-1.2.1 → consolelib-1.2.2}/ConsoleLib.egg-info/dependency_links.txt +0 -0
- {consolelib-1.2.1 → consolelib-1.2.2}/ConsoleLib.egg-info/top_level.txt +0 -0
- {consolelib-1.2.1 → consolelib-1.2.2}/README.md +0 -0
- {consolelib-1.2.1 → consolelib-1.2.2}/setup.cfg +0 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# ConsoleLib - The best Console Renderer of the Python
|
|
2
|
+
# By: Suleiman
|
|
3
|
+
# Copyright © Suleiman 2026
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
import subprocess as CMD
|
|
8
|
+
import math
|
|
9
|
+
class Render:
|
|
10
|
+
@staticmethod
|
|
11
|
+
def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
|
|
12
|
+
if clear_before_draw:
|
|
13
|
+
os.system("cls" if os.name == "nt" else "clear")
|
|
14
|
+
field = [[default_char for _ in range(width)] for _ in range(height)]
|
|
15
|
+
if points:
|
|
16
|
+
for item in points:
|
|
17
|
+
if len(item) == 3:
|
|
18
|
+
x, y, char = item
|
|
19
|
+
if 0 <= x < width and 0 <= y < height:
|
|
20
|
+
field[y][x] = char
|
|
21
|
+
for row in field:
|
|
22
|
+
print(''.join(row))
|
|
23
|
+
@staticmethod
|
|
24
|
+
def get_line_points(x1, y1, x2, y2, char='#'):
|
|
25
|
+
points = []
|
|
26
|
+
dx = abs(x2 - x1)
|
|
27
|
+
dy = abs(y2 - y1)
|
|
28
|
+
sx = 1 if x1 < x2 else -1
|
|
29
|
+
sy = 1 if y1 < y2 else -1
|
|
30
|
+
err = dx - dy
|
|
31
|
+
while True:
|
|
32
|
+
points.append((x1, y1, char))
|
|
33
|
+
if x1 == x2 and y1 == y2:
|
|
34
|
+
break
|
|
35
|
+
e2 = err * 2
|
|
36
|
+
if e2 > -dy:
|
|
37
|
+
err -= dy
|
|
38
|
+
x1 += sx
|
|
39
|
+
if e2 < dx:
|
|
40
|
+
err += dx
|
|
41
|
+
y1 += sy
|
|
42
|
+
return points
|
|
43
|
+
@staticmethod
|
|
44
|
+
def get_circle_points(cx, cy, r, char='#'):
|
|
45
|
+
points = []
|
|
46
|
+
for angle in range(0, 360, 5):
|
|
47
|
+
rad = angle * math.pi / 180
|
|
48
|
+
x = int(cx + r * math.cos(rad))
|
|
49
|
+
y = int(cy + r * math.sin(rad))
|
|
50
|
+
points.append((x, y, char))
|
|
51
|
+
return points
|
|
52
|
+
@staticmethod
|
|
53
|
+
def get_filled_circle_points(cx, cy, r, char='#'):
|
|
54
|
+
points = []
|
|
55
|
+
for y in range(cy - r, cy + r + 1):
|
|
56
|
+
for x in range(cx - r, cx + r + 1):
|
|
57
|
+
if (x - cx) ** 2 + (y - cy) ** 2 <= r ** 2:
|
|
58
|
+
points.append((x, y, char))
|
|
59
|
+
return points
|
|
60
|
+
@staticmethod
|
|
61
|
+
def get_rect_points(x1, y1, x2, y2, char='#'):
|
|
62
|
+
points = []
|
|
63
|
+
for x in range(x1, x2 + 1):
|
|
64
|
+
points.append((x, y1, char))
|
|
65
|
+
points.append((x, y2, char))
|
|
66
|
+
for y in range(y1, y2 + 1):
|
|
67
|
+
points.append((x1, y, char))
|
|
68
|
+
points.append((x2, y, char))
|
|
69
|
+
return points
|
|
70
|
+
@staticmethod
|
|
71
|
+
def get_fill_rect_points(x1, y1, x2, y2, char='#'):
|
|
72
|
+
points = []
|
|
73
|
+
for y in range(y1, y2 + 1):
|
|
74
|
+
for x in range(x1, x2 + 1):
|
|
75
|
+
points.append((x, y, char))
|
|
76
|
+
return points
|
|
77
|
+
@staticmethod
|
|
78
|
+
def get_text_points(x, y, text, char=None):
|
|
79
|
+
points = []
|
|
80
|
+
if char is None:
|
|
81
|
+
for i, ch in enumerate(text):
|
|
82
|
+
points.append((x + i, y, ch))
|
|
83
|
+
else:
|
|
84
|
+
for i in range(len(text)):
|
|
85
|
+
points.append((x + i, y, char))
|
|
86
|
+
return points
|
|
87
|
+
@staticmethod
|
|
88
|
+
def get_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
|
|
89
|
+
points = []
|
|
90
|
+
points.extend(Render.get_line_points(x1, y1, x2, y2, char))
|
|
91
|
+
points.extend(Render.get_line_points(x2, y2, x3, y3, char))
|
|
92
|
+
points.extend(Render.get_line_points(x3, y3, x1, y1, char))
|
|
93
|
+
return points
|
|
94
|
+
@staticmethod
|
|
95
|
+
def get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char='#'):
|
|
96
|
+
points = []
|
|
97
|
+
min_x = min(x1, x2, x3)
|
|
98
|
+
max_x = max(x1, x2, x3)
|
|
99
|
+
min_y = min(y1, y2, y3)
|
|
100
|
+
max_y = max(y1, y2, y3)
|
|
101
|
+
for y in range(min_y, max_y + 1):
|
|
102
|
+
for x in range(min_x, max_x + 1):
|
|
103
|
+
if Render._point_in_triangle(x, y, x1, y1, x2, y2, x3, y3):
|
|
104
|
+
points.append((x, y, char))
|
|
105
|
+
return points
|
|
106
|
+
@staticmethod
|
|
107
|
+
def get_heart_points(cx, cy, size=5, char='#'):
|
|
108
|
+
points = []
|
|
109
|
+
for y in range(-size, size + 1):
|
|
110
|
+
for x in range(-size, size + 1):
|
|
111
|
+
if ((x * x + y * y - size * size) ** 3 <= size * size * x * x * y * y * 0.5):
|
|
112
|
+
points.append((cx + x, cy - y, char))
|
|
113
|
+
return points
|
|
114
|
+
@staticmethod
|
|
115
|
+
def get_star_points(cx, cy, radius=5, points_count=5, char='*'):
|
|
116
|
+
points = []
|
|
117
|
+
angle = -math.pi / 2
|
|
118
|
+
step = math.pi / points_count
|
|
119
|
+
outer_points = []
|
|
120
|
+
inner_points = []
|
|
121
|
+
for i in range(points_count * 2):
|
|
122
|
+
r = radius if i % 2 == 0 else radius * 0.4
|
|
123
|
+
x = cx + r * math.cos(angle + i * step)
|
|
124
|
+
y = cy + r * math.sin(angle + i * step)
|
|
125
|
+
if i % 2 == 0:
|
|
126
|
+
outer_points.append((x, y))
|
|
127
|
+
else:
|
|
128
|
+
inner_points.append((x, y))
|
|
129
|
+
for i in range(points_count):
|
|
130
|
+
p1 = outer_points[i]
|
|
131
|
+
p2 = inner_points[i]
|
|
132
|
+
p3 = outer_points[(i + 1) % points_count]
|
|
133
|
+
points.extend(Render.get_line_points(int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1]), char))
|
|
134
|
+
points.extend(Render.get_line_points(int(p2[0]), int(p2[1]), int(p3[0]), int(p3[1]), char))
|
|
135
|
+
return points
|
|
136
|
+
@staticmethod
|
|
137
|
+
def get_bezier_points(x1, y1, x2, y2, x3, y3, steps=20, char='#'):
|
|
138
|
+
points = []
|
|
139
|
+
for t in range(steps + 1):
|
|
140
|
+
t = t / steps
|
|
141
|
+
x = (1 - t) ** 2 * x1 + 2 * (1 - t) * t * x2 + t ** 2 * x3
|
|
142
|
+
y = (1 - t) ** 2 * y1 + 2 * (1 - t) * t * y2 + t ** 2 * y3
|
|
143
|
+
points.append((int(x), int(y), char))
|
|
144
|
+
return points
|
|
145
|
+
@staticmethod
|
|
146
|
+
def get_wave_points(cx, cy, amplitude=5, length=20, char='~'):
|
|
147
|
+
points = []
|
|
148
|
+
for x in range(length):
|
|
149
|
+
y = cy + int(amplitude * math.sin(x * 0.5))
|
|
150
|
+
points.append((cx + x, y, char))
|
|
151
|
+
return points
|
|
152
|
+
@staticmethod
|
|
153
|
+
def _point_in_triangle(px, py, x1, y1, x2, y2, x3, y3):
|
|
154
|
+
def sign(a, b, c):
|
|
155
|
+
return (a[0] - c[0]) * (b[1] - c[1]) - (b[0] - c[0]) * (a[1] - c[1])
|
|
156
|
+
p = (px, py)
|
|
157
|
+
d1 = sign(p, (x2, y2), (x1, y1))
|
|
158
|
+
d2 = sign(p, (x3, y3), (x2, y2))
|
|
159
|
+
d3 = sign(p, (x1, y1), (x3, y3))
|
|
160
|
+
has_neg = (d1 < 0) or (d2 < 0) or (d3 < 0)
|
|
161
|
+
has_pos = (d1 > 0) or (d2 > 0) or (d3 > 0)
|
|
162
|
+
return not (has_neg and has_pos)
|
|
163
|
+
@staticmethod
|
|
164
|
+
def draw_line(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
165
|
+
points = Render.get_line_points(x1, y1, x2, y2, char)
|
|
166
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
167
|
+
@staticmethod
|
|
168
|
+
def draw_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
|
|
169
|
+
points = Render.get_circle_points(cx, cy, r, char)
|
|
170
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
171
|
+
@staticmethod
|
|
172
|
+
def draw_filled_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
|
|
173
|
+
points = Render.get_filled_circle_points(cx, cy, r, char)
|
|
174
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
175
|
+
@staticmethod
|
|
176
|
+
def draw_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
177
|
+
points = Render.get_rect_points(x1, y1, x2, y2, char)
|
|
178
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
179
|
+
@staticmethod
|
|
180
|
+
def fill_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
181
|
+
points = Render.get_fill_rect_points(x1, y1, x2, y2, char)
|
|
182
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
183
|
+
@staticmethod
|
|
184
|
+
def draw_text(x, y, text, width=80, height=25, clear_before_draw=False):
|
|
185
|
+
points = Render.get_text_points(x, y, text)
|
|
186
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
187
|
+
@staticmethod
|
|
188
|
+
def draw_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False):
|
|
189
|
+
points = Render.get_triangle_points(x1, y1, x2, y2, x3, y3, char)
|
|
190
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
191
|
+
@staticmethod
|
|
192
|
+
def fill_triangle(x1, y1, x2, y2, x3, y3, char='#', width=80, height=25, clear_before_draw=False):
|
|
193
|
+
points = Render.get_filled_triangle_points(x1, y1, x2, y2, x3, y3, char)
|
|
194
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
195
|
+
@staticmethod
|
|
196
|
+
def draw_heart(cx, cy, size=5, char='#', width=80, height=25, clear_before_draw=False):
|
|
197
|
+
points = Render.get_heart_points(cx, cy, size, char)
|
|
198
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
199
|
+
@staticmethod
|
|
200
|
+
def draw_star(cx, cy, radius=5, points_count=5, char='#', width=80, height=25, clear_before_draw=False):
|
|
201
|
+
points = Render.get_star_points(cx, cy, radius, points_count, char)
|
|
202
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
203
|
+
@staticmethod
|
|
204
|
+
def draw_bezier(x1, y1, x2, y2, x3, y3, steps=20, char='#', width=80, height=25, clear_before_draw=False):
|
|
205
|
+
points = Render.get_bezier_points(x1, y1, x2, y2, x3, y3, steps, char)
|
|
206
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
207
|
+
@staticmethod
|
|
208
|
+
def draw_wave(cx, cy, amplitude=5, length=20, char='~', width=80, height=25, clear_before_draw=False):
|
|
209
|
+
points = Render.get_wave_points(cx, cy, amplitude, length, char)
|
|
210
|
+
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
211
|
+
class ConsoleInfo:
|
|
212
|
+
@staticmethod
|
|
213
|
+
def GetConsole():
|
|
214
|
+
return sys.stdout
|
|
215
|
+
@staticmethod
|
|
216
|
+
def GetPipVer():
|
|
217
|
+
try:
|
|
218
|
+
result = CMD.run(['python', '-m', 'pip', '--version'], capture_output=True, text=True, check=True)
|
|
219
|
+
return result.stdout.strip()
|
|
220
|
+
except CMD.CalledProcessError as e:
|
|
221
|
+
return f"Error: pip not found (code {e.returncode})"
|
|
222
|
+
except FileNotFoundError:
|
|
223
|
+
return "Error: Python not installed or not in PATH"
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ConsoleLib"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.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"
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import os, sys, time
|
|
2
|
-
import subprocess as CMD
|
|
3
|
-
class Render:
|
|
4
|
-
@staticmethod
|
|
5
|
-
def DrawPic(points=None, width=80, height=25, clear_before_draw=False, default_char=' '):
|
|
6
|
-
if clear_before_draw:
|
|
7
|
-
os.system("cls" if os.name == "nt" else "clear")
|
|
8
|
-
field = [[default_char for _ in range(width)] for _ in range(height)]
|
|
9
|
-
if points:
|
|
10
|
-
for item in points:
|
|
11
|
-
if len(item) == 3:
|
|
12
|
-
x, y, char = item
|
|
13
|
-
if 0 <= x < width and 0 <= y < height:
|
|
14
|
-
field[y][x] = char
|
|
15
|
-
for row in field:
|
|
16
|
-
print(''.join(row))
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def draw_line(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
20
|
-
points = []
|
|
21
|
-
dx = abs(x2 - x1)
|
|
22
|
-
dy = abs(y2 - y1)
|
|
23
|
-
sx = 1 if x1 < x2 else -1
|
|
24
|
-
sy = 1 if y1 < y2 else -1
|
|
25
|
-
err = dx - dy
|
|
26
|
-
while True:
|
|
27
|
-
points.append((x1, y1, char))
|
|
28
|
-
if x1 == x2 and y1 == y2:
|
|
29
|
-
break
|
|
30
|
-
e2 = err * 2
|
|
31
|
-
if e2 > -dy:
|
|
32
|
-
err -= dy
|
|
33
|
-
x1 += sx
|
|
34
|
-
if e2 < dx:
|
|
35
|
-
err += dx
|
|
36
|
-
y1 += sy
|
|
37
|
-
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
38
|
-
|
|
39
|
-
@staticmethod
|
|
40
|
-
def draw_circle(cx, cy, r, char='#', width=80, height=25, clear_before_draw=False):
|
|
41
|
-
import math
|
|
42
|
-
points = []
|
|
43
|
-
for angle in range(0, 360, 5):
|
|
44
|
-
rad = angle * 3.14159 / 180
|
|
45
|
-
x = int(cx + r * math.cos(rad))
|
|
46
|
-
y = int(cy + r * math.sin(rad))
|
|
47
|
-
points.append((x, y, char))
|
|
48
|
-
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
49
|
-
|
|
50
|
-
@staticmethod
|
|
51
|
-
def draw_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
52
|
-
points = []
|
|
53
|
-
for x in range(x1, x2 + 1):
|
|
54
|
-
points.append((x, y1, char))
|
|
55
|
-
points.append((x, y2, char))
|
|
56
|
-
for y in range(y1, y2 + 1):
|
|
57
|
-
points.append((x1, y, char))
|
|
58
|
-
points.append((x2, y, char))
|
|
59
|
-
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
60
|
-
|
|
61
|
-
@staticmethod
|
|
62
|
-
def fill_rect(x1, y1, x2, y2, char='#', width=80, height=25, clear_before_draw=False):
|
|
63
|
-
points = []
|
|
64
|
-
for y in range(y1, y2 + 1):
|
|
65
|
-
for x in range(x1, x2 + 1):
|
|
66
|
-
points.append((x, y, char))
|
|
67
|
-
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
68
|
-
|
|
69
|
-
@staticmethod
|
|
70
|
-
def draw_text(x, y, text, width=80, height=25, clear_before_draw=False):
|
|
71
|
-
points = []
|
|
72
|
-
for i, char in enumerate(text):
|
|
73
|
-
points.append((x + i, y, char))
|
|
74
|
-
Render.DrawPic(points=points, width=width, height=height, clear_before_draw=clear_before_draw)
|
|
75
|
-
class ConsoleInfo:
|
|
76
|
-
@staticmethod
|
|
77
|
-
def GetConsole():
|
|
78
|
-
return sys.stdout
|
|
79
|
-
|
|
80
|
-
@staticmethod
|
|
81
|
-
def GetPipVer():
|
|
82
|
-
try:
|
|
83
|
-
result = CMD.run(['python', '-m', 'pip', '--version'], capture_output=True, text=True, check=True)
|
|
84
|
-
return result.stdout.strip()
|
|
85
|
-
except CMD.CalledProcessError as e:
|
|
86
|
-
return f"Error: pip not found (code {e.returncode})"
|
|
87
|
-
except FileNotFoundError:
|
|
88
|
-
return "Error: Python not installed or not in PATH"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|