nercone-modern 1.10.0__py3-none-any.whl → 1.11.1__py3-none-any.whl
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.
- nercone_modern/__main__.py +4 -6
- nercone_modern/color.py +9 -1
- nercone_modern/logging.py +17 -52
- nercone_modern/progressbar.py +9 -9
- nercone_modern/text.py +8 -0
- {nercone_modern-1.10.0.dist-info → nercone_modern-1.11.1.dist-info}/METADATA +1 -1
- nercone_modern-1.11.1.dist-info/RECORD +9 -0
- {nercone_modern-1.10.0.dist-info → nercone_modern-1.11.1.dist-info}/WHEEL +1 -1
- nercone_modern-1.10.0.dist-info/RECORD +0 -9
nercone_modern/__main__.py
CHANGED
|
@@ -10,11 +10,9 @@ import time
|
|
|
10
10
|
from nercone_modern.logging import ModernLogging
|
|
11
11
|
from nercone_modern.progressbar import ModernProgressBar
|
|
12
12
|
|
|
13
|
-
logger0 = ModernLogging("Demo", display_level="DEBUG"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
logger1 = ModernLogging("Main", display_level="DEBUG", show_proc=show_proc, show_level=show_level)
|
|
17
|
-
logger2 = ModernLogging("Sub", display_level="DEBUG", show_proc=show_proc, show_level=show_level)
|
|
13
|
+
logger0 = ModernLogging("Demo", display_level="DEBUG")
|
|
14
|
+
logger1 = ModernLogging("Main", display_level="DEBUG")
|
|
15
|
+
logger2 = ModernLogging("Sub", display_level="DEBUG")
|
|
18
16
|
|
|
19
17
|
try:
|
|
20
18
|
logger1.log("This is a debug message", "DEBUG")
|
|
@@ -52,4 +50,4 @@ try:
|
|
|
52
50
|
progress_bar2.finish()
|
|
53
51
|
except KeyboardInterrupt:
|
|
54
52
|
print()
|
|
55
|
-
|
|
53
|
+
logger0.log("Aborted.", "INFO")
|
nercone_modern/color.py
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# -- nercone-modern --------------------------------------------- #
|
|
4
|
+
# color.py on nercone-modern #
|
|
5
|
+
# Made by DiamondGotCat, Licensed under MIT License #
|
|
6
|
+
# Copyright (c) 2025 DiamondGotCat #
|
|
7
|
+
# ---------------------------------------------- DiamondGotCat -- #
|
|
8
|
+
|
|
1
9
|
class ModernColor:
|
|
2
10
|
def color_by_code(color_code: int | str = 0):
|
|
3
11
|
return f"\033[{color_code}m"
|
|
4
12
|
|
|
5
13
|
def color(color_name: str = "reset"):
|
|
6
|
-
if color_name
|
|
14
|
+
if color_name in ("reset", "default"):
|
|
7
15
|
return ModernColor.color_by_code(0)
|
|
8
16
|
elif color_name == "black":
|
|
9
17
|
return ModernColor.color_by_code(30)
|
nercone_modern/logging.py
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import sys
|
|
10
10
|
from .color import ModernColor
|
|
11
|
+
from datetime import datetime, timezone
|
|
11
12
|
|
|
12
13
|
ModernLoggingLevels = ["DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"]
|
|
13
14
|
MAX_LOG_LEVEL_WIDTH = max(len(level) for level in ModernLoggingLevels)
|
|
@@ -29,6 +30,7 @@ LEVEL_ALIASES = {
|
|
|
29
30
|
_last_process = None
|
|
30
31
|
_last_level = None
|
|
31
32
|
_max_proc_width = 0
|
|
33
|
+
_max_prefix_width = 20
|
|
32
34
|
|
|
33
35
|
def normalize_level(level: str) -> str:
|
|
34
36
|
level = level.strip().upper()
|
|
@@ -43,12 +45,11 @@ def is_higher_priority(level_a: str, level_b: str) -> bool:
|
|
|
43
45
|
raise ValueError(f"Unknown log level: {level_a} or {level_b}")
|
|
44
46
|
|
|
45
47
|
class ModernLogging:
|
|
46
|
-
def __init__(self, process_name: str = "App", display_level: str = "INFO", filepath: str | None = None
|
|
48
|
+
def __init__(self, process_name: str = "App", display_level: str = "INFO", filepath: str | None = None):
|
|
47
49
|
self.process_name = process_name
|
|
48
50
|
self.display_level = display_level
|
|
49
51
|
self.filepath = filepath
|
|
50
|
-
self.
|
|
51
|
-
self.show_level = show_level
|
|
52
|
+
self.short_mode = short_mode
|
|
52
53
|
global _max_proc_width
|
|
53
54
|
_max_proc_width = max(_max_proc_width, len(process_name))
|
|
54
55
|
|
|
@@ -175,11 +176,8 @@ class ModernLogging:
|
|
|
175
176
|
return lower_map[stripped.lower()]
|
|
176
177
|
return None
|
|
177
178
|
|
|
178
|
-
def make(self, message: str = "", level_text: str = "INFO", level_color: str | None = None
|
|
179
|
+
def make(self, message: str = "", level_text: str = "INFO", level_color: str | None = None):
|
|
179
180
|
level_text = normalize_level(level_text.strip().upper())
|
|
180
|
-
system_show_proc = (self.process_name != _last_process)
|
|
181
|
-
system_show_level = system_show_proc or (level_text != _last_level)
|
|
182
|
-
|
|
183
181
|
if not level_color:
|
|
184
182
|
if level_text == "DEBUG":
|
|
185
183
|
level_color = 'gray'
|
|
@@ -193,48 +191,15 @@ class ModernLogging:
|
|
|
193
191
|
level_color = 'red'
|
|
194
192
|
else:
|
|
195
193
|
level_color = 'blue'
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return self._make(message=message, level_text=level_text, level_color=level_color, show_proc=show_proc, show_level=show_level, system_show_proc=system_show_proc, system_show_level=system_show_level)
|
|
210
|
-
|
|
211
|
-
def _make(self, message: str = "", level_text: str = "INFO", level_color: str = "blue", show_proc: bool = False, show_level: bool = False, system_show_proc: bool = True, system_show_level: bool = True):
|
|
212
|
-
global _max_proc_width
|
|
213
|
-
level_width = max(MAX_LOG_LEVEL_WIDTH, len(level_text))
|
|
214
|
-
color_bar = f"{ModernColor.color(level_color)}|{ModernColor.color('reset')}"
|
|
215
|
-
|
|
216
|
-
if not show_proc and not show_level:
|
|
217
|
-
prefix = ""
|
|
218
|
-
else:
|
|
219
|
-
prefix = ""
|
|
220
|
-
if show_proc:
|
|
221
|
-
if system_show_proc:
|
|
222
|
-
proc_part = self.process_name[:_max_proc_width].ljust(_max_proc_width)
|
|
223
|
-
else:
|
|
224
|
-
proc_part = " " * _max_proc_width
|
|
225
|
-
prefix += proc_part
|
|
226
|
-
prefix += " "
|
|
227
|
-
else:
|
|
228
|
-
if show_level:
|
|
229
|
-
prefix += " " * (_max_proc_width + 1)
|
|
230
|
-
if show_level:
|
|
231
|
-
if system_show_level:
|
|
232
|
-
level_part = level_text.ljust(level_width)
|
|
233
|
-
level_part = f"{ModernColor.color(level_color)}{level_part}{ModernColor.color('reset')}"
|
|
234
|
-
else:
|
|
235
|
-
level_part = " " * level_width
|
|
236
|
-
prefix += level_part
|
|
237
|
-
if show_proc:
|
|
238
|
-
prefix += " " * (_max_proc_width + 1)
|
|
239
|
-
|
|
240
|
-
return f"{prefix}{color_bar} {str(message)}"
|
|
194
|
+
return self._make(message=message, level_text=level_text, level_color=level_color)
|
|
195
|
+
|
|
196
|
+
def _current_time(self) -> str:
|
|
197
|
+
return datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
198
|
+
|
|
199
|
+
def _make(self, message: str = "", level_text: str = "INFO", level_color: str = "blue"):
|
|
200
|
+
global _max_proc_width, _max_prefix_width
|
|
201
|
+
timestamp = self._current_time()
|
|
202
|
+
log_level = level_text.ljust(MAX_LOG_LEVEL_WIDTH)
|
|
203
|
+
proc_name = self.process_name.ljust(_max_proc_width)
|
|
204
|
+
_max_prefix_width = max(_max_prefix_width, len(f"[{timestamp} {log_level} {proc_name}]"))
|
|
205
|
+
return f"[{timestamp} {ModernColor.color(level_color)}{log_level}{ModernColor.color('reset')} {proc_name}] {message}"
|
nercone_modern/progressbar.py
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import sys
|
|
10
10
|
import threading
|
|
11
|
+
from . import logging
|
|
11
12
|
from .color import ModernColor
|
|
12
13
|
from .logging import ModernLogging
|
|
13
14
|
|
|
@@ -16,7 +17,7 @@ class ModernProgressBar:
|
|
|
16
17
|
_last_rendered = False
|
|
17
18
|
_lock = threading.RLock()
|
|
18
19
|
|
|
19
|
-
def __init__(self, total: int, process_name: str, spinner_mode: bool = False, primary_bar: str = "-", secondary_bar: str = "-", centor_bar: str = "-", primary_color: str = "blue", secondary_color: str = "
|
|
20
|
+
def __init__(self, total: int, process_name: str, spinner_mode: bool = False, primary_bar: str = "-", secondary_bar: str = "-", centor_bar: str = "-", primary_color: str = "blue", secondary_color: str = "green", third_color: str = "white", box_color: str = "reset", box_left: str = "[", box_right: str = "]"):
|
|
20
21
|
self.total = total
|
|
21
22
|
self.process_name = process_name.strip()
|
|
22
23
|
self.spinner_mode = spinner_mode
|
|
@@ -25,11 +26,10 @@ class ModernProgressBar:
|
|
|
25
26
|
self.centor_bar = centor_bar
|
|
26
27
|
self.primary_color = primary_color
|
|
27
28
|
self.secondary_color = secondary_color
|
|
29
|
+
self.third_color = third_color
|
|
28
30
|
self.box_color = box_color
|
|
29
31
|
self.box_left = box_left
|
|
30
32
|
self.box_right = box_right
|
|
31
|
-
self.show_vertical_bar = show_vertical_bar
|
|
32
|
-
self.vertical_bar_color = vertical_bar_color
|
|
33
33
|
self.current = 0
|
|
34
34
|
self.index = len(ModernProgressBar._active_bars)
|
|
35
35
|
ModernProgressBar._active_bars.append(self)
|
|
@@ -147,10 +147,10 @@ class ModernProgressBar:
|
|
|
147
147
|
status = ""
|
|
148
148
|
if not (final or (self.spinner_mode and self._spinner_ready)):
|
|
149
149
|
if self.spinner_mode:
|
|
150
|
-
status = f"{
|
|
150
|
+
status = f" ({' ' * total_width}/{' ' * total_width})"
|
|
151
151
|
else:
|
|
152
|
-
status = f"{self.
|
|
153
|
-
line = f"{ModernColor.color(self.
|
|
152
|
+
status = f" ({self.current:>{total_width}}/{self.total:>{total_width}})"
|
|
153
|
+
line = f"{ModernColor.color(self.box_color)}{self.box_left}{ModernColor.color('reset')}{ModernColor.color('gray')}{bar}{ModernColor.color('reset')}{ModernColor.color(self.box_color)}{self.box_right}{ModernColor.color('reset')} {ModernColor.color(self.primary_color)}{proc_name}{ModernColor.color('reset')} {ModernColor.color(self.secondary_color)}{percentage_alt if self.spinner_mode else percentage}{ModernColor.color('reset')}{ModernColor.color('gray')}{status}{ModernColor.color('reset')} {self.message}"
|
|
154
154
|
total_move_up = self.log_lines + (len(ModernProgressBar._active_bars) - self.index)
|
|
155
155
|
if total_move_up > 0:
|
|
156
156
|
sys.stdout.write(f"\033[{total_move_up}A")
|
|
@@ -164,7 +164,7 @@ class ModernProgressBar:
|
|
|
164
164
|
sys.stdout.flush()
|
|
165
165
|
|
|
166
166
|
def _progress_bar(self, progress: int, advance_spinner: bool = True):
|
|
167
|
-
bar_length =
|
|
167
|
+
bar_length = logging._max_prefix_width - 3
|
|
168
168
|
if not self._should_spin():
|
|
169
169
|
if self.current == self.total:
|
|
170
170
|
center_bar = ""
|
|
@@ -173,7 +173,7 @@ class ModernProgressBar:
|
|
|
173
173
|
if self.current <= 0 and not self._spinner_ready:
|
|
174
174
|
return f"{ModernColor.color('gray')}{self.secondary_bar * (bar_length + 1)}"
|
|
175
175
|
filled_length = int(progress * bar_length) + 1
|
|
176
|
-
return f"{ModernColor.color(self.primary_color)}{self.primary_bar * filled_length}{ModernColor.color(self.
|
|
176
|
+
return f"{ModernColor.color(self.primary_color)}{self.primary_bar * filled_length}{ModernColor.color(self.third_color)}{center_bar}{ModernColor.color('gray')}{self.secondary_bar * (bar_length - filled_length)}"
|
|
177
177
|
else:
|
|
178
178
|
if self.current <= 0 and not self._spinner_ready:
|
|
179
179
|
return f"{ModernColor.color('gray')}{'-' * (bar_length + 1)}"
|
|
@@ -182,7 +182,7 @@ class ModernProgressBar:
|
|
|
182
182
|
spinner_start_bar_length = bar_length - spinner_end_bar_length
|
|
183
183
|
if advance_spinner:
|
|
184
184
|
self.spinner_step = (self.spinner_step + 1) % (bar_length + 1)
|
|
185
|
-
return f"{ModernColor.color('gray')}{'-' * spinner_start_bar_length}{ModernColor.color(self.
|
|
185
|
+
return f"{ModernColor.color('gray')}{'-' * spinner_start_bar_length}{ModernColor.color(self.third_color)}{'-' * spinner_symbol_length}{ModernColor.color('gray')}{'-' * spinner_end_bar_length}"
|
|
186
186
|
|
|
187
187
|
def _should_spin(self):
|
|
188
188
|
return self.spinner_mode and self._spinner_ready
|
nercone_modern/text.py
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# -- nercone-modern --------------------------------------------- #
|
|
4
|
+
# text.py on nercone-modern #
|
|
5
|
+
# Made by DiamondGotCat, Licensed under MIT License #
|
|
6
|
+
# Copyright (c) 2025 DiamondGotCat #
|
|
7
|
+
# ---------------------------------------------- DiamondGotCat -- #
|
|
8
|
+
|
|
1
9
|
from typing import Union
|
|
2
10
|
from .color import ModernColor
|
|
3
11
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
nercone_modern/__init__.py,sha256=ArF3T8FdWIhwGcL4MfYcHqMse3n5gjuyzbLNlcqRcxs,443
|
|
2
|
+
nercone_modern/__main__.py,sha256=PbC8jASQJvSOUOW1m106Cei4kpJPFwxPcwxfPMjckUU,2083
|
|
3
|
+
nercone_modern/color.py,sha256=nWzIDKIvHeHX57wZT4YYXztKWLSShRqOTPzQa4L30qI,1646
|
|
4
|
+
nercone_modern/logging.py,sha256=N4PWiC9Jv2U1yKc5LrhZHt0abcSSxGYpLmqdHusxfTA,8711
|
|
5
|
+
nercone_modern/progressbar.py,sha256=VYohOwKyxTtyhNehG0O4zOtPt3wGvVxAelQ-ye8hg-k,8796
|
|
6
|
+
nercone_modern/text.py,sha256=W1Wn_9E7O70AyuOVjb9GZqOdUoyqoHIyGPViBdgHShs,1396
|
|
7
|
+
nercone_modern-1.11.1.dist-info/WHEEL,sha256=3id4o64OvRm9dUknh3mMJNcfoTRK08ua5cU6DFyVy-4,79
|
|
8
|
+
nercone_modern-1.11.1.dist-info/METADATA,sha256=-3kmPQGXeTXK4IbnQv1AkZrWNBAKKQR1fPpS1uZzyNw,6128
|
|
9
|
+
nercone_modern-1.11.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
nercone_modern/__init__.py,sha256=ArF3T8FdWIhwGcL4MfYcHqMse3n5gjuyzbLNlcqRcxs,443
|
|
2
|
-
nercone_modern/__main__.py,sha256=tiCwzvs4N0J9_vFoA7eaQqkSIhVcDxUQ9uLPNeSQVWo,2475
|
|
3
|
-
nercone_modern/color.py,sha256=e2P9WXeGosHLCAasdE7IQW29GPZOVDMLsUCsLj6hBkM,1268
|
|
4
|
-
nercone_modern/logging.py,sha256=61ixjR37-ewS1RUwnNZnkNGQEBazhiSJJv5g-rLq834,10158
|
|
5
|
-
nercone_modern/progressbar.py,sha256=KO4HgYrLYl1Dv8IX_xH-cNdrr2Y6uK3JwZzp73sAamM,8973
|
|
6
|
-
nercone_modern/text.py,sha256=eGxGQOJ3b-783ocLibkG62cOcYD4HLG_3diA52tU8jI,1031
|
|
7
|
-
nercone_modern-1.10.0.dist-info/WHEEL,sha256=YUH1mBqsx8Dh2cQG2rlcuRYUhJddG9iClegy4IgnHik,79
|
|
8
|
-
nercone_modern-1.10.0.dist-info/METADATA,sha256=gqH_2-eNbvxSjzoB9h-47q9DSyc_ptQqX3OuQkPAqKI,6128
|
|
9
|
-
nercone_modern-1.10.0.dist-info/RECORD,,
|