xulbux 1.7.2__py3-none-any.whl → 1.8.0__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.
Potentially problematic release.
This version of xulbux might be problematic. Click here for more details.
- xulbux/__init__.py +17 -19
- xulbux/{xx_code.py → code.py} +3 -3
- xulbux/{xx_color.py → color.py} +1 -1
- xulbux/{xx_console.py → console.py} +352 -200
- xulbux/{xx_data.py → data.py} +14 -14
- xulbux/{xx_env_path.py → env_path.py} +1 -1
- xulbux/{xx_file.py → file.py} +1 -1
- xulbux/{xx_format_codes.py → format_codes.py} +24 -22
- xulbux/{xx_json.py → json.py} +3 -3
- xulbux/{xx_system.py → system.py} +11 -11
- xulbux-1.8.0.dist-info/METADATA +190 -0
- xulbux-1.8.0.dist-info/RECORD +18 -0
- xulbux-1.8.0.dist-info/entry_points.txt +2 -0
- xulbux/_cli_.py +0 -46
- xulbux/_consts_.py +0 -180
- xulbux-1.7.2.dist-info/METADATA +0 -170
- xulbux-1.7.2.dist-info/RECORD +0 -21
- xulbux-1.7.2.dist-info/entry_points.txt +0 -3
- xulbux-1.7.2.dist-info/licenses/LICENSE +0 -21
- /xulbux/{xx_path.py → path.py} +0 -0
- /xulbux/{xx_regex.py → regex.py} +0 -0
- /xulbux/{xx_string.py → string.py} +0 -0
- {xulbux-1.7.2.dist-info → xulbux-1.8.0.dist-info}/WHEEL +0 -0
- {xulbux-1.7.2.dist-info → xulbux-1.8.0.dist-info}/top_level.txt +0 -0
xulbux/{xx_data.py → data.py}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from .
|
|
2
|
-
from .
|
|
3
|
-
from .
|
|
1
|
+
from .base.consts import COLOR
|
|
2
|
+
from .format_codes import FormatCodes
|
|
3
|
+
from .string import String
|
|
4
4
|
|
|
5
5
|
from typing import TypeAlias, Optional, Union, Any
|
|
6
6
|
import base64 as _base64
|
|
@@ -420,11 +420,11 @@ class Data:
|
|
|
420
420
|
elif not isinstance(_syntax_highlighting, dict):
|
|
421
421
|
raise TypeError(f"Expected 'syntax_highlighting' to be a dict or bool. Got: {type(_syntax_highlighting)}")
|
|
422
422
|
_syntax_hl = {
|
|
423
|
-
"str": (f"[{COLOR.
|
|
424
|
-
"number": (f"[{COLOR.
|
|
425
|
-
"literal": (f"[{COLOR.
|
|
426
|
-
"type": (f"[i|{COLOR.
|
|
427
|
-
"punctuation": (f"[{COLOR.
|
|
423
|
+
"str": (f"[{COLOR.BLUE}]", "[_c]"),
|
|
424
|
+
"number": (f"[{COLOR.MAGENTA}]", "[_c]"),
|
|
425
|
+
"literal": (f"[{COLOR.CYAN}]", "[_c]"),
|
|
426
|
+
"type": (f"[i|{COLOR.LIGHT_BLUE}]", "[_i|_c]"),
|
|
427
|
+
"punctuation": (f"[{COLOR.DARK_GRAY}]", "[_c]"),
|
|
428
428
|
}
|
|
429
429
|
_syntax_hl.update({
|
|
430
430
|
k: (f"[{v}]", "[_]") if k in _syntax_hl and v not in ("", None) else ("", "")
|
|
@@ -564,14 +564,14 @@ class Data:
|
|
|
564
564
|
part. The formatting can be changed by simply adding the key with the new
|
|
565
565
|
value inside the `syntax_highlighting` dictionary.\n
|
|
566
566
|
The keys with their default values are:
|
|
567
|
-
- `str: COLOR.
|
|
568
|
-
- `number: COLOR.
|
|
569
|
-
- `literal: COLOR.
|
|
570
|
-
- `type: "i|" + COLOR.
|
|
571
|
-
- `punctuation: COLOR.
|
|
567
|
+
- `str: COLOR.BLUE`
|
|
568
|
+
- `number: COLOR.MAGENTA`
|
|
569
|
+
- `literal: COLOR.CYAN`
|
|
570
|
+
- `type: "i|" + COLOR.LIGHT_BLUE`
|
|
571
|
+
- `punctuation: COLOR.DARK_GRAY`\n
|
|
572
572
|
For no syntax highlighting, set `syntax_highlighting` to `False` or `None`.\n
|
|
573
573
|
------------------------------------------------------------------------------
|
|
574
|
-
For more detailed information about formatting codes, see `
|
|
574
|
+
For more detailed information about formatting codes, see `format_codes`
|
|
575
575
|
module documentation."""
|
|
576
576
|
FormatCodes.print(
|
|
577
577
|
Data.to_str(data, indent, compactness, max_width, sep, as_json, syntax_highlighting),
|
xulbux/{xx_file.py → file.py}
RENAMED
|
@@ -56,11 +56,13 @@ the formatting code:
|
|
|
56
56
|
- `[(255, 0, 136)]`
|
|
57
57
|
- `[255, 0, 136]`
|
|
58
58
|
- HEX colors:
|
|
59
|
-
Change the text color directly with a HEX color inside the square brackets. (
|
|
59
|
+
Change the text color directly with a HEX color inside the square brackets. (Whether the `RGB` or `RRGGBB` HEX format is used,
|
|
60
60
|
and if there's a `#` or `0x` prefix, doesn't matter.)
|
|
61
61
|
Examples:
|
|
62
|
+
- `[0x7788FF]`
|
|
62
63
|
- `[#7788FF]`
|
|
63
64
|
- `[7788FF]`
|
|
65
|
+
- `[0x78F]`
|
|
64
66
|
- `[#78F]`
|
|
65
67
|
- `[78F]`
|
|
66
68
|
- background RGB / HEX colors:
|
|
@@ -155,10 +157,10 @@ Per default, you can also use `+` and `-` to get lighter and darker `default_col
|
|
|
155
157
|
All of these lighten/darken formatting codes are treated as invalid if no `default_color` is set.
|
|
156
158
|
"""
|
|
157
159
|
|
|
158
|
-
from .
|
|
159
|
-
from .
|
|
160
|
-
from .
|
|
161
|
-
from .
|
|
160
|
+
from .base.consts import ANSI
|
|
161
|
+
from .string import String
|
|
162
|
+
from .regex import Regex, Match, Pattern
|
|
163
|
+
from .color import Color, rgba, Rgba, Hexa
|
|
162
164
|
|
|
163
165
|
from typing import Optional, cast
|
|
164
166
|
import ctypes as _ctypes
|
|
@@ -185,7 +187,7 @@ _PREFIX_RX: dict[str, str] = {
|
|
|
185
187
|
_COMPILED: dict[str, Pattern] = { # PRECOMPILE REGULAR EXPRESSIONS
|
|
186
188
|
"*": _re.compile(r"\[\s*([^]_]*?)\s*\*\s*([^]_]*?)\]"),
|
|
187
189
|
"*color": _re.compile(r"\[\s*([^]_]*?)\s*\*c(?:olor)?\s*([^]_]*?)\]"),
|
|
188
|
-
"ansi_seq": _re.compile(ANSI.
|
|
190
|
+
"ansi_seq": _re.compile(ANSI.CHAR + r"(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])"),
|
|
189
191
|
"formatting": _rx.compile(
|
|
190
192
|
Regex.brackets("[", "]", is_group=True, ignore_in_strings=False)
|
|
191
193
|
+ r"(?:\s*([/\\]?)\s*"
|
|
@@ -224,7 +226,7 @@ class FormatCodes:
|
|
|
224
226
|
"""A print function, whose print values can be formatted using formatting codes.\n
|
|
225
227
|
-----------------------------------------------------------------------------------
|
|
226
228
|
For exact information about how to use special formatting codes, see the
|
|
227
|
-
`
|
|
229
|
+
`format_codes` module documentation."""
|
|
228
230
|
FormatCodes.__config_console()
|
|
229
231
|
_sys.stdout.write(FormatCodes.to_ansi(sep.join(map(str, values)) + end, default_color, brightness_steps))
|
|
230
232
|
if flush:
|
|
@@ -243,11 +245,11 @@ class FormatCodes:
|
|
|
243
245
|
user confirms the input and the program continues to run.\n
|
|
244
246
|
-------------------------------------------------------------------------
|
|
245
247
|
For exact information about how to use special formatting codes, see the
|
|
246
|
-
`
|
|
248
|
+
`format_codes` module documentation."""
|
|
247
249
|
FormatCodes.__config_console()
|
|
248
250
|
user_input = input(FormatCodes.to_ansi(str(prompt), default_color, brightness_steps))
|
|
249
251
|
if reset_ansi:
|
|
250
|
-
_sys.stdout.write(f"{ANSI.
|
|
252
|
+
_sys.stdout.write(f"{ANSI.CHAR}[0m")
|
|
251
253
|
return user_input
|
|
252
254
|
|
|
253
255
|
@staticmethod
|
|
@@ -261,7 +263,7 @@ class FormatCodes:
|
|
|
261
263
|
"""Convert the formatting codes inside a string to ANSI formatting.\n
|
|
262
264
|
-------------------------------------------------------------------------
|
|
263
265
|
For exact information about how to use special formatting codes, see the
|
|
264
|
-
`
|
|
266
|
+
`format_codes` module documentation."""
|
|
265
267
|
if not isinstance(string, str):
|
|
266
268
|
string = str(string)
|
|
267
269
|
use_default, default_specified = False, default_color is not None
|
|
@@ -282,7 +284,7 @@ class FormatCodes:
|
|
|
282
284
|
string = _COMPILED["*"].sub(r"[\1_\2]", string) # REPLACE `[…|*|…]` WITH `[…|_|…]`
|
|
283
285
|
|
|
284
286
|
def is_valid_color(color: str) -> bool:
|
|
285
|
-
return bool((color in ANSI.
|
|
287
|
+
return bool((color in ANSI.COLOR_MAP) or Color.is_valid_rgba(color) or Color.is_valid_hexa(color))
|
|
286
288
|
|
|
287
289
|
def replace_keys(match: Match) -> str:
|
|
288
290
|
_formats = formats = match.group(1)
|
|
@@ -337,12 +339,12 @@ class FormatCodes:
|
|
|
337
339
|
reset_keys.append(f"_{k}")
|
|
338
340
|
ansi_resets = [
|
|
339
341
|
r for k in reset_keys if (r := FormatCodes.__get_replacement(k, default_color, brightness_steps)
|
|
340
|
-
).startswith(f"{ANSI.
|
|
342
|
+
).startswith(f"{ANSI.CHAR}{ANSI.START}")
|
|
341
343
|
]
|
|
342
344
|
else:
|
|
343
345
|
ansi_resets = []
|
|
344
|
-
if not (len(ansi_formats) == 1 and ansi_formats[0].count(f"{ANSI.
|
|
345
|
-
f.startswith(f"{ANSI.
|
|
346
|
+
if not (len(ansi_formats) == 1 and ansi_formats[0].count(f"{ANSI.CHAR}{ANSI.START}") >= 1) and not all(
|
|
347
|
+
f.startswith(f"{ANSI.CHAR}{ANSI.START}") for f in ansi_formats): # FORMATTING WAS INVALID
|
|
346
348
|
return match.group(0)
|
|
347
349
|
elif formats_escaped: # FORMATTING WAS VALID BUT ESCAPED
|
|
348
350
|
return f"[{_formats}]({auto_reset_txt})" if auto_reset_txt else f"[{_formats}]"
|
|
@@ -361,7 +363,7 @@ class FormatCodes:
|
|
|
361
363
|
@staticmethod
|
|
362
364
|
def escape_ansi(ansi_string: str) -> str:
|
|
363
365
|
"""Escapes all ANSI codes in the string, so they are visible when output to the console."""
|
|
364
|
-
return ansi_string.replace(ANSI.
|
|
366
|
+
return ansi_string.replace(ANSI.CHAR, ANSI.ESCAPED_CHAR)
|
|
365
367
|
|
|
366
368
|
@staticmethod
|
|
367
369
|
def remove_ansi(
|
|
@@ -435,7 +437,7 @@ class FormatCodes:
|
|
|
435
437
|
return None
|
|
436
438
|
_default_color: tuple[int, int, int] = tuple(default_color)[:3]
|
|
437
439
|
if brightness_steps is None or (format_key and _COMPILED["bg?_default"].search(format_key)):
|
|
438
|
-
return (ANSI.
|
|
440
|
+
return (ANSI.SEQ_BG_COLOR if format_key and _COMPILED["bg_default"].search(format_key) else ANSI.SEQ_COLOR).format(
|
|
439
441
|
*_default_color
|
|
440
442
|
)
|
|
441
443
|
if format_key is None or not (format_key in _modifiers[0] or format_key in _modifiers[1]):
|
|
@@ -457,7 +459,7 @@ class FormatCodes:
|
|
|
457
459
|
new_rgb = tuple(Color.adjust_lightness(default_color, (brightness_steps / 100) * adjust))
|
|
458
460
|
elif modifiers in _modifiers[1]:
|
|
459
461
|
new_rgb = tuple(Color.adjust_lightness(default_color, -(brightness_steps / 100) * adjust))
|
|
460
|
-
return (ANSI.
|
|
462
|
+
return (ANSI.SEQ_BG_COLOR if is_bg else ANSI.SEQ_COLOR).format(*new_rgb[:3])
|
|
461
463
|
|
|
462
464
|
@staticmethod
|
|
463
465
|
def __get_replacement(format_key: str, default_color: Optional[rgba], brightness_steps: int = 20) -> str:
|
|
@@ -468,11 +470,11 @@ class FormatCodes:
|
|
|
468
470
|
if default_color and (new_default_color := FormatCodes.__get_default_ansi(default_color, format_key,
|
|
469
471
|
brightness_steps)):
|
|
470
472
|
return new_default_color
|
|
471
|
-
for map_key in ANSI.
|
|
473
|
+
for map_key in ANSI.CODES_MAP:
|
|
472
474
|
if (isinstance(map_key, tuple) and format_key in map_key) or format_key == map_key:
|
|
473
475
|
return _ANSI_SEQ_1.format(
|
|
474
476
|
next((
|
|
475
|
-
v for k, v in ANSI.
|
|
477
|
+
v for k, v in ANSI.CODES_MAP.items() if format_key == k or (isinstance(k, tuple) and format_key in k)
|
|
476
478
|
), None)
|
|
477
479
|
)
|
|
478
480
|
rgb_match = _COMPILED["rgb"].match(format_key)
|
|
@@ -482,13 +484,13 @@ class FormatCodes:
|
|
|
482
484
|
is_bg = rgb_match.group(1)
|
|
483
485
|
r, g, b = map(int, rgb_match.groups()[1:])
|
|
484
486
|
if Color.is_valid_rgba((r, g, b)):
|
|
485
|
-
return ANSI.
|
|
487
|
+
return ANSI.SEQ_BG_COLOR.format(r, g, b) if is_bg else ANSI.SEQ_COLOR.format(r, g, b)
|
|
486
488
|
elif hex_match:
|
|
487
489
|
is_bg = hex_match.group(1)
|
|
488
490
|
rgb = Color.to_rgba(hex_match.group(2))
|
|
489
491
|
return (
|
|
490
|
-
ANSI.
|
|
491
|
-
if is_bg else ANSI.
|
|
492
|
+
ANSI.SEQ_BG_COLOR.format(rgb[0], rgb[1], rgb[2])
|
|
493
|
+
if is_bg else ANSI.SEQ_COLOR.format(rgb[0], rgb[1], rgb[2])
|
|
492
494
|
)
|
|
493
495
|
except Exception:
|
|
494
496
|
pass
|
xulbux/{xx_json.py → json.py}
RENAMED
|
@@ -23,16 +23,16 @@ class _IsElevated:
|
|
|
23
23
|
class System:
|
|
24
24
|
|
|
25
25
|
is_elevated: bool = _IsElevated() # type: ignore[assignment]
|
|
26
|
-
"""Is `True` if the current process has
|
|
27
|
-
elevated privileges and `False` otherwise."""
|
|
26
|
+
"""Is `True` if the current process has elevated privileges and `False` otherwise."""
|
|
28
27
|
|
|
29
28
|
@staticmethod
|
|
30
|
-
def restart(prompt: object =
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
- `
|
|
34
|
-
- `
|
|
35
|
-
- `
|
|
29
|
+
def restart(prompt: object = "", wait: int = 0, continue_program: bool = False, force: bool = False) -> None:
|
|
30
|
+
"""Restarts the system with some advanced options\n
|
|
31
|
+
--------------------------------------------------------------------------------------------------
|
|
32
|
+
- `prompt` -⠀the message to be displayed in the systems restart notification
|
|
33
|
+
- `wait` -⠀the time to wait until restarting in seconds
|
|
34
|
+
- `continue_program` -⠀whether to continue the current Python program after calling this function
|
|
35
|
+
- `force` -⠀whether to force a restart even if other processes are still running"""
|
|
36
36
|
system = _platform.system().lower()
|
|
37
37
|
if system == "windows":
|
|
38
38
|
if not force:
|
|
@@ -69,9 +69,9 @@ class System:
|
|
|
69
69
|
@staticmethod
|
|
70
70
|
def check_libs(lib_names: list[str], install_missing: bool = False, confirm_install: bool = True) -> Optional[list[str]]:
|
|
71
71
|
"""Checks if the given list of libraries are installed. If not:
|
|
72
|
-
- If `install_missing` is
|
|
73
|
-
- If `install_missing` is
|
|
74
|
-
- If `confirm_install` is
|
|
72
|
+
- If `install_missing` is false, the missing libraries will be returned as a list.
|
|
73
|
+
- If `install_missing` is true, the missing libraries will be installed.
|
|
74
|
+
- If `confirm_install` is true, the user will first be asked if they want to install the missing libraries."""
|
|
75
75
|
missing = []
|
|
76
76
|
for lib in lib_names:
|
|
77
77
|
try:
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xulbux
|
|
3
|
+
Version: 1.8.0
|
|
4
|
+
Summary: A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler.
|
|
5
|
+
Author-email: XulbuX <xulbux.real@gmail.com>
|
|
6
|
+
Maintainer-email: XulbuX <xulbux.real@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/XulbuX/PythonLibraryXulbuX
|
|
9
|
+
Project-URL: Documentation, https://github.com/XulbuX/PythonLibraryXulbuX/wiki
|
|
10
|
+
Project-URL: Source Code, https://github.com/XulbuX/PythonLibraryXulbuX/tree/main/src
|
|
11
|
+
Project-URL: Changelog, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md
|
|
12
|
+
Project-URL: Bug Reports, https://github.com/XulbuX/PythonLibraryXulbuX/issues
|
|
13
|
+
Project-URL: Stats, https://clickpy.clickhouse.com/dashboard/xulbux
|
|
14
|
+
Project-URL: License, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/LICENSE
|
|
15
|
+
Keywords: args,arguments,attributes,classes,client,cmd,code,codes,color,commands,console,constants,consts,conversion,convert,data,debug,easier,env,environment,error,file,format,formatting,functions,helper,hex,hexa,hsl,hsla,info,input,json,library,log,logging,methods,nice,operations,path,presets,pretty,printing,properties,python,re,regex,rgb,rgba,string,structures,system,tools,types,utility,warn,warning,xulbux
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Intended Audience :: Developers
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
Requires-Dist: keyboard>=0.13.5
|
|
27
|
+
Requires-Dist: prompt_toolkit>=3.0.41
|
|
28
|
+
Requires-Dist: pyperclip>=1.9.0
|
|
29
|
+
Requires-Dist: regex>=2023.10.3
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: black>=23.7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: flake8-pyproject>=1.2.3; extra == "dev"
|
|
33
|
+
Requires-Dist: flake8>=6.1.0; extra == "dev"
|
|
34
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest>=7.4.2; extra == "dev"
|
|
36
|
+
|
|
37
|
+
# **XulbuX**
|
|
38
|
+
|
|
39
|
+
[](https://pypi.org/project/xulbux) [](https://clickpy.clickhouse.com/dashboard/xulbux) [](https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/LICENSE) [](https://github.com/XulbuX/PythonLibraryXulbuX/commits) [](https://github.com/XulbuX/PythonLibraryXulbuX/issues)
|
|
40
|
+
|
|
41
|
+
**XulbuX** is a library that contains many useful classes, types, and functions,
|
|
42
|
+
ranging from console logging and working with colors to file management and system operations.
|
|
43
|
+
The library is designed to simplify common programming tasks and improve code readability through its collection of tools.
|
|
44
|
+
|
|
45
|
+
For precise information about the library, see the library's [**documentation**](https://github.com/XulbuX/PythonLibraryXulbuX/wiki).<br>
|
|
46
|
+
For the libraries latest changes and updates, see the [**change log**](https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md).
|
|
47
|
+
|
|
48
|
+
### The best modules, you have to check out:
|
|
49
|
+
|
|
50
|
+
[](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/format_codes) [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/console) [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/color)
|
|
51
|
+
|
|
52
|
+
<br>
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
Run the following commands in a console with administrator privileges, so the actions take effect for all users.
|
|
57
|
+
|
|
58
|
+
Install the library and all its dependencies with the command:
|
|
59
|
+
```console
|
|
60
|
+
pip install xulbux
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Upgrade the library and all its dependencies to their latest available version with the command:
|
|
64
|
+
```console
|
|
65
|
+
pip install --upgrade xulbux
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
<br>
|
|
69
|
+
|
|
70
|
+
## CLI Commands
|
|
71
|
+
|
|
72
|
+
When the library is installed, the following commands are available in the console:
|
|
73
|
+
| Command | Description |
|
|
74
|
+
| :------------ | :--------------------------------------- |
|
|
75
|
+
| `xulbux-help` | shows some information about the library |
|
|
76
|
+
|
|
77
|
+
<br>
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
Import the full library under the alias `xx`, so its constants, classes, methods, and types are accessible with `xx.CONSTANT.value`, `xx.Class.method()`, `xx.type()`:
|
|
82
|
+
```python
|
|
83
|
+
import xulbux as xx
|
|
84
|
+
```
|
|
85
|
+
So you don't have to import the full library under an alias, you can also import only certain parts of the library's contents:
|
|
86
|
+
```python
|
|
87
|
+
# LIBRARY CONSTANTS
|
|
88
|
+
from xulbux.base.consts import COLOR, CHARS, ANSI
|
|
89
|
+
# Main Classes
|
|
90
|
+
from xulbux import Code, Color, Console, ...
|
|
91
|
+
# module specific imports
|
|
92
|
+
from xulbux.color import rgba, hsla, hexa
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
<br>
|
|
96
|
+
|
|
97
|
+
## Modules
|
|
98
|
+
|
|
99
|
+
| Module | Short Description |
|
|
100
|
+
| :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------ |
|
|
101
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/base) | includes more modules like library constants |
|
|
102
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/code) | advanced code-string operations (*changing the indent, finding function calls, ...*) |
|
|
103
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/color) | everything around colors (*converting, blending, searching colors in strings, ...*) |
|
|
104
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/console) | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
|
|
105
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/data) | advanced operations with data structures (*compare, generate path IDs, pretty print, ...*) |
|
|
106
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/env_path) | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
|
|
107
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/file) | advanced working with files (*create files, rename file-extensions, ...*) |
|
|
108
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/format_codes) | easy pretty printing using custom format codes (*print, inputs, format codes to ANSI, ...*) |
|
|
109
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/json) | advanced working with json files (*read, create, update, ...*) |
|
|
110
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/path) | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
|
|
111
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/regex) | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
|
|
112
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/string) | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
|
|
113
|
+
| [](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/system) | advanced system actions (*restart with message, check installed Python libs, ...*) |
|
|
114
|
+
|
|
115
|
+
<br>
|
|
116
|
+
|
|
117
|
+
## Example Usage
|
|
118
|
+
|
|
119
|
+
This is what it could look like using this library for a simple but ultra good-looking color converter:
|
|
120
|
+
```python
|
|
121
|
+
from xulbux.base.consts import COLOR, CHARS
|
|
122
|
+
from xulbux.color import hexa
|
|
123
|
+
from xulbux import Console
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def main() -> None:
|
|
127
|
+
|
|
128
|
+
# LET THE USER ENTER A HEXA COLOR IN ANY HEXA FORMAT
|
|
129
|
+
input_clr = Console.input(
|
|
130
|
+
"[b](Enter a HEXA color in any format) > ",
|
|
131
|
+
start="\n",
|
|
132
|
+
placeholder="#7075FF",
|
|
133
|
+
max_len=7,
|
|
134
|
+
allowed_chars=CHARS.HEX_DIGITS,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# ANNOUNCE INDEXING THE INPUT COLOR
|
|
138
|
+
Console.log(
|
|
139
|
+
"INDEX",
|
|
140
|
+
"Indexing the input HEXA color...",
|
|
141
|
+
start="\n",
|
|
142
|
+
title_bg_color=COLOR.BLUE,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
# TRY TO CONVERT THE INPUT COLOR INTO A hexa() COLOR
|
|
147
|
+
hexa_color = hexa(input_clr)
|
|
148
|
+
|
|
149
|
+
except ValueError:
|
|
150
|
+
# ANNOUNCE THE ERROR AND EXIT THE PROGRAM
|
|
151
|
+
Console.fail(
|
|
152
|
+
"The input HEXA color is invalid.",
|
|
153
|
+
end="\n\n",
|
|
154
|
+
exit=True,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# ANNOUNCE STARTING THE CONVERSION
|
|
158
|
+
Console.log(
|
|
159
|
+
"CONVERT",
|
|
160
|
+
"Converting the HEXA color into different types...",
|
|
161
|
+
title_bg_color=COLOR.TANGERINE,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
# CONVERT THE HEXA COLOR INTO THE TWO OTHER COLOR TYPES
|
|
165
|
+
rgba_color = hexa_color.to_rgba()
|
|
166
|
+
hsla_color = hexa_color.to_hsla()
|
|
167
|
+
|
|
168
|
+
# ANNOUNCE THE SUCCESSFUL CONVERSION
|
|
169
|
+
Console.done(
|
|
170
|
+
"Successfully converted color into different types.",
|
|
171
|
+
end="\n\n",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
# PRETTY PRINT THE COLOR IN DIFFERENT TYPES
|
|
175
|
+
Console.log_box_bordered(
|
|
176
|
+
f"[b](HEXA:) [i|white]({hexa_color})",
|
|
177
|
+
f"[b](RGBA:) [i|white]({rgba_color})",
|
|
178
|
+
f"[b](HSLA:) [i|white]({hsla_color})",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
183
|
+
main()
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
<br>
|
|
187
|
+
<br>
|
|
188
|
+
|
|
189
|
+
--------------------------------------------------------------
|
|
190
|
+
[View this library on **PyPI**](https://pypi.org/project/xulbux)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
xulbux/__init__.py,sha256=ee9vPsQXG50BOKoVLqUmcClEs-94eYHN3572x0AC3BY,817
|
|
2
|
+
xulbux/code.py,sha256=CLA3wh6mTvcXTlQgBeFaaLIBciHvXWqVM56rAtfO-JE,6102
|
|
3
|
+
xulbux/color.py,sha256=XCB05xBSEz6-dpX9yVkMB2zTSdTH01MfUazJEthL_zM,49741
|
|
4
|
+
xulbux/console.py,sha256=J--5Ma2H3-YPT21pT92J4mNgu-0h_vJJ8M1BLOKbHWc,42773
|
|
5
|
+
xulbux/data.py,sha256=hB9JxrSC7_6kelJ_TwOaapNrlig-jiyNZS3YoiJX8F8,30884
|
|
6
|
+
xulbux/env_path.py,sha256=HGOSffdIDubzczsXe6umyqotrzqhIW83QBkISAamXT8,4157
|
|
7
|
+
xulbux/file.py,sha256=7pa0-WS_DpXq7HRB1fLS6Acd9CM-ozXPpNJvMqCW4fw,2624
|
|
8
|
+
xulbux/format_codes.py,sha256=94VyxnUZI2dS1glteNs7izKYrTI_W2pukFGF5f9k72E,24720
|
|
9
|
+
xulbux/json.py,sha256=Ei5FdCjfM0FrrAEBmuuTcexl7mUY4eirXr-QPct2OS0,7448
|
|
10
|
+
xulbux/path.py,sha256=lLAEVZrW0TAwCewlONFVQcQ_8tVn9LTJZVOZpeGvE5s,7673
|
|
11
|
+
xulbux/regex.py,sha256=_BtMHRDNcD9zF4SL87dQuUVZcYGfZx9H5YNSDiEtzm8,8059
|
|
12
|
+
xulbux/string.py,sha256=QaTo0TQ9m_2USNgQNaVw5ivQt-A1E-e5x8OpIB3xIlY,5561
|
|
13
|
+
xulbux/system.py,sha256=Y5x719Ocwi93VJ6DVE8NR_Js7FQ6QT5wmtjX9FAsw9U,6582
|
|
14
|
+
xulbux-1.8.0.dist-info/METADATA,sha256=Gk3Oj08lJRZuRWrUZ5bkPVjjWy0HIGS4h9UazzDrzP8,11041
|
|
15
|
+
xulbux-1.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
xulbux-1.8.0.dist-info/entry_points.txt,sha256=aYh89GfiBOB8vw2VPgC6rhBinhnJoAL1kig-3lq_zkg,58
|
|
17
|
+
xulbux-1.8.0.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
|
|
18
|
+
xulbux-1.8.0.dist-info/RECORD,,
|
xulbux/_cli_.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
from ._consts_ import COLOR
|
|
2
|
-
from . import __version__
|
|
3
|
-
from .xx_format_codes import FormatCodes
|
|
4
|
-
from .xx_console import Console
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def help_command():
|
|
8
|
-
"""Show some info about the library, with a brief explanation of how to use it."""
|
|
9
|
-
color = {
|
|
10
|
-
"class": COLOR.tangerine,
|
|
11
|
-
"const": COLOR.red,
|
|
12
|
-
"func": COLOR.cyan,
|
|
13
|
-
"import": COLOR.neongreen,
|
|
14
|
-
"lib": COLOR.orange,
|
|
15
|
-
"punctuators": COLOR.darkgray,
|
|
16
|
-
"code_border": COLOR.gray,
|
|
17
|
-
}
|
|
18
|
-
FormatCodes.print(
|
|
19
|
-
rf""" [_|b|#7075FF] __ __
|
|
20
|
-
[b|#7075FF] _ __ __ __/ / / /_ __ ___ __
|
|
21
|
-
[b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
|
|
22
|
-
[b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
|
|
23
|
-
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{COLOR.gray}|#000] v[b]{__version__} [*]
|
|
24
|
-
|
|
25
|
-
[i|{COLOR.coral}]A TON OF COOL FUNCTIONS, YOU NEED![*]
|
|
26
|
-
|
|
27
|
-
[b|#FCFCFF]Usage:[*]
|
|
28
|
-
[dim|{color['code_border']}](╭────────────────────────────────────────────────────╮)
|
|
29
|
-
[dim|{color['code_border']}](│) [{color['punctuators']}]# CONSTANTS[*] [dim|{color['code_border']}](│)
|
|
30
|
-
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['const']}]COLOR[{color['punctuators']}], [{color['const']}]CHARS[{color['punctuators']}], [{color['const']}]ANSI[*] [dim|{color['code_border']}](│)
|
|
31
|
-
[dim|{color['code_border']}](│) [{color['punctuators']}]# Classes[*] [dim|{color['code_border']}](│)
|
|
32
|
-
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['class']}]Code[{color['punctuators']}], [{color['class']}]Color[{color['punctuators']}], [{color['class']}]Console[{color['punctuators']}], ...[*] [dim|{color['code_border']}](│)
|
|
33
|
-
[dim|{color['code_border']}](│) [{color['punctuators']}]# types[*] [dim|{color['code_border']}](│)
|
|
34
|
-
[dim|{color['code_border']}](│) [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['func']}]rgba[{color['punctuators']}], [{color['func']}]hsla[{color['punctuators']}], [{color['func']}]hexa[*] [dim|{color['code_border']}](│)
|
|
35
|
-
[dim|{color['code_border']}](╰────────────────────────────────────────────────────╯)
|
|
36
|
-
[b|#FCFCFF]Documentation:[*]
|
|
37
|
-
[dim|{color['code_border']}](╭────────────────────────────────────────────────────╮)
|
|
38
|
-
[dim|{color['code_border']}](│) [#DADADD]For more information see the GitHub page. [dim|{color['code_border']}](│)
|
|
39
|
-
[dim|{color['code_border']}](│) [u|#8085FF](https://github.com/XulbuX/PythonLibraryXulbuX/wiki) [dim|{color['code_border']}](│)
|
|
40
|
-
[dim|{color['code_border']}](╰────────────────────────────────────────────────────╯)
|
|
41
|
-
[_]
|
|
42
|
-
[dim](Press any key to exit...)
|
|
43
|
-
""",
|
|
44
|
-
default_color=COLOR.text
|
|
45
|
-
)
|
|
46
|
-
Console.pause_exit(pause=True)
|