xulbux 1.8.0__py3-none-any.whl → 1.8.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.

Potentially problematic release.


This version of xulbux might be problematic. Click here for more details.

xulbux/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.8.0"
1
+ __version__ = "1.8.1"
2
2
 
3
3
  __author__ = "XulbuX"
4
4
  __email__ = "xulbux.real@gmail.com"
xulbux/base/consts.py ADDED
@@ -0,0 +1,173 @@
1
+ from typing import TypeAlias
2
+
3
+
4
+ FormattableString: TypeAlias = str
5
+ """A `str` object that is made to be formatted with the `.format()` method."""
6
+
7
+
8
+ class COLOR:
9
+ """Hexa color presets."""
10
+
11
+ WHITE = "#F1F2FF"
12
+ LIGHT_GRAY = "#B6B7C0"
13
+ GRAY = "#7B7C8D"
14
+ DARK_GRAY = "#67686C"
15
+ BLACK = "#202125"
16
+ RED = "#FF606A"
17
+ CORAL = "#FF7069"
18
+ ORANGE = "#FF876A"
19
+ TANGERINE = "#FF9962"
20
+ GOLD = "#FFAF60"
21
+ YELLOW = "#FFD260"
22
+ LIME = "#C9F16E"
23
+ GREEN = "#7EE787"
24
+ NEON_GREEN = "#4CFF85"
25
+ TEAL = "#50EAAF"
26
+ CYAN = "#3EDEE6"
27
+ ICE = "#77DBEF"
28
+ LIGHT_BLUE = "#60AAFF"
29
+ BLUE = "#8085FF"
30
+ LAVENDER = "#9B7DFF"
31
+ PURPLE = "#AD68FF"
32
+ MAGENTA = "#C860FF"
33
+ PINK = "#F162EF"
34
+ ROSE = "#FF609F"
35
+
36
+
37
+ class CHARS:
38
+ """Text character sets."""
39
+
40
+ class _AllTextChars:
41
+ pass
42
+
43
+ ALL = _AllTextChars
44
+ """Code to signal that all characters are allowed."""
45
+
46
+ DIGITS = "0123456789"
47
+ """Digits: `0`-`9`"""
48
+ FLOAT_DIGITS = DIGITS + "."
49
+ """Digits: `0`-`9` with decimal point `.`"""
50
+ HEX_DIGITS = DIGITS + "#abcdefABCDEF"
51
+ """Digits: `0`-`9` Letters: `a`-`f` `A`-`F` and a hashtag `#`"""
52
+
53
+ LOWERCASE = "abcdefghijklmnopqrstuvwxyz"
54
+ """Lowercase letters `a`-`z`"""
55
+ LOWERCASE_EXTENDED = LOWERCASE + "äëïöüÿàèìòùáéíóúýâêîôûãñõåæç"
56
+ """Lowercase letters `a`-`z` with all lowercase diacritic letters."""
57
+ UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
58
+ """Uppercase letters `A`-`Z`"""
59
+ UPPERCASE_EXTENDED = UPPERCASE + "ÄËÏÖÜÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÅÆÇß"
60
+ """Uppercase letters `A`-`Z` with all uppercase diacritic letters."""
61
+
62
+ LETTERS = LOWERCASE + UPPERCASE
63
+ """Lowercase and uppercase letters `a`-`z` and `A`-`Z`"""
64
+ LETTERS_EXTENDED = LOWERCASE_EXTENDED + UPPERCASE_EXTENDED
65
+ """Lowercase and uppercase letters `a`-`z` `A`-`Z` and all diacritic letters."""
66
+
67
+ SPECIAL_ASCII = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
68
+ """All ASCII special characters."""
69
+ SPECIAL_ASCII_EXTENDED = SPECIAL_ASCII + "ø£Ø×ƒªº¿®¬½¼¡«»░▒▓│┤©╣║╗╝¢¥┐└┴┬├─┼╚╔╩╦╠═╬¤ðÐı┘┌█▄¦▀µþÞ¯´≡­±‗¾¶§÷¸°¨·¹³²■ "
70
+ """All ASCII special characters with the extended ASCII special characters."""
71
+ STANDARD_ASCII = SPECIAL_ASCII + DIGITS + LETTERS
72
+ """All standard ASCII characters."""
73
+ FULL_ASCII = SPECIAL_ASCII_EXTENDED + DIGITS + LETTERS_EXTENDED
74
+ """All characters in the ASCII table."""
75
+
76
+
77
+ class ANSI:
78
+ """Constants and methods for use of ANSI escape codes"""
79
+
80
+ ESCAPED_CHAR = "\\x1b"
81
+ """The printable ANSI escape character."""
82
+ CHAR = char = "\x1b"
83
+ """The ANSI escape character."""
84
+ START = start = "["
85
+ """The start of an ANSI escape sequence."""
86
+ SEP = sep = ";"
87
+ """The separator between ANSI escape sequence parts."""
88
+ END = end = "m"
89
+ """The end of an ANSI escape sequence."""
90
+
91
+ @classmethod
92
+ def seq(cls, parts: int = 1) -> FormattableString:
93
+ """Generate an ANSI sequence with `parts` amount of placeholders."""
94
+ return cls.CHAR + cls.START + cls.SEP.join(["{}" for _ in range(parts)]) + cls.END
95
+
96
+ SEQ_COLOR: FormattableString = CHAR + START + "38" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
97
+ """The ANSI escape sequence for setting the text RGB color."""
98
+ SEQ_BG_COLOR: FormattableString = CHAR + START + "48" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
99
+ """The ANSI escape sequence for setting the background RGB color."""
100
+
101
+ COLOR_MAP: tuple[str, ...] = (
102
+ ########### DEFAULT CONSOLE COLOR NAMES ############
103
+ "black",
104
+ "red",
105
+ "green",
106
+ "yellow",
107
+ "blue",
108
+ "magenta",
109
+ "cyan",
110
+ "white",
111
+ )
112
+ """The console default color names."""
113
+
114
+ CODES_MAP: dict[str | tuple[str, ...], int] = {
115
+ ################# SPECIFIC RESETS ##################
116
+ "_": 0,
117
+ ("_bold", "_b"): 22,
118
+ ("_dim", "_d"): 22,
119
+ ("_italic", "_i"): 23,
120
+ ("_underline", "_u"): 24,
121
+ ("_double-underline", "_du"): 24,
122
+ ("_inverse", "_invert", "_in"): 27,
123
+ ("_hidden", "_hide", "_h"): 28,
124
+ ("_strikethrough", "_s"): 29,
125
+ ("_color", "_c"): 39,
126
+ ("_background", "_bg"): 49,
127
+ ################### TEXT STYLES ####################
128
+ ("bold", "b"): 1,
129
+ ("dim", "d"): 2,
130
+ ("italic", "i"): 3,
131
+ ("underline", "u"): 4,
132
+ ("inverse", "invert", "in"): 7,
133
+ ("hidden", "hide", "h"): 8,
134
+ ("strikethrough", "s"): 9,
135
+ ("double-underline", "du"): 21,
136
+ ################## DEFAULT COLORS ##################
137
+ "black": 30,
138
+ "red": 31,
139
+ "green": 32,
140
+ "yellow": 33,
141
+ "blue": 34,
142
+ "magenta": 35,
143
+ "cyan": 36,
144
+ "white": 37,
145
+ ############## BRIGHT DEFAULT COLORS ###############
146
+ "br:black": 90,
147
+ "br:red": 91,
148
+ "br:green": 92,
149
+ "br:yellow": 93,
150
+ "br:blue": 94,
151
+ "br:magenta": 95,
152
+ "br:cyan": 96,
153
+ "br:white": 97,
154
+ ############ DEFAULT BACKGROUND COLORS #############
155
+ "bg:black": 40,
156
+ "bg:red": 41,
157
+ "bg:green": 42,
158
+ "bg:yellow": 43,
159
+ "bg:blue": 44,
160
+ "bg:magenta": 45,
161
+ "bg:cyan": 46,
162
+ "bg:white": 47,
163
+ ######### BRIGHT DEFAULT BACKGROUND COLORS #########
164
+ "bg:br:black": 100,
165
+ "bg:br:red": 101,
166
+ "bg:br:green": 102,
167
+ "bg:br:yellow": 103,
168
+ "bg:br:blue": 104,
169
+ "bg:br:magenta": 105,
170
+ "bg:br:cyan": 106,
171
+ "bg:br:white": 107,
172
+ }
173
+ """All custom format keys and their corresponding ANSI format number codes."""
xulbux/cli/help.py ADDED
@@ -0,0 +1,45 @@
1
+ from .. import __version__
2
+ from ..base.consts import COLOR
3
+ from ..format_codes import FormatCodes
4
+ from ..console import Console
5
+
6
+
7
+ CLR = {
8
+ "class": COLOR.TANGERINE,
9
+ "const": COLOR.RED,
10
+ "func": COLOR.CYAN,
11
+ "import": COLOR.NEON_GREEN,
12
+ "lib": COLOR.ORANGE,
13
+ "punctuators": COLOR.DARK_GRAY,
14
+ "code_border": COLOR.GRAY,
15
+ }
16
+ HELP = FormatCodes.to_ansi(
17
+ rf""" [_|b|#7075FF] __ __
18
+ [b|#7075FF] _ __ __ __/ / / /_ __ ___ __
19
+ [b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
20
+ [b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
21
+ [b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{COLOR.GRAY}|#000] v[b]{__version__} [*]
22
+
23
+ [i|{COLOR.CORAL}]A TON OF COOL FUNCTIONS, YOU NEED![*]
24
+
25
+ [b|#FCFCFF]Usage:[*]
26
+ [dim|{CLR['code_border']}](╭────────────────────────────────────────────────────╮)
27
+ [dim|{CLR['code_border']}](│) [{CLR['punctuators']}]# LIBRARY CONSTANTS[*] [dim|{CLR['code_border']}](│)
28
+ [dim|{CLR['code_border']}](│) [{CLR['import']}]from [{CLR['lib']}]xulbux[{CLR['punctuators']}].[{CLR['lib']}]base[{CLR['punctuators']}].[{CLR['lib']}]consts [{CLR['import']}]import [{CLR['const']}]COLOR[{CLR['punctuators']}], [{CLR['const']}]CHARS[{CLR['punctuators']}], [{CLR['const']}]ANSI[*] [dim|{CLR['code_border']}](│)
29
+ [dim|{CLR['code_border']}](│) [{CLR['punctuators']}]# Main Classes[*] [dim|{CLR['code_border']}](│)
30
+ [dim|{CLR['code_border']}](│) [{CLR['import']}]from [{CLR['lib']}]xulbux [{CLR['import']}]import [{CLR['class']}]Code[{CLR['punctuators']}], [{CLR['class']}]Color[{CLR['punctuators']}], [{CLR['class']}]Console[{CLR['punctuators']}], ...[*] [dim|{CLR['code_border']}](│)
31
+ [dim|{CLR['code_border']}](│) [{CLR['punctuators']}]# module specific imports[*] [dim|{CLR['code_border']}](│)
32
+ [dim|{CLR['code_border']}](│) [{CLR['import']}]from [{CLR['lib']}]xulbux[{CLR['punctuators']}].[{CLR['lib']}]color [{CLR['import']}]import [{CLR['func']}]rgba[{CLR['punctuators']}], [{CLR['func']}]hsla[{CLR['punctuators']}], [{CLR['func']}]hexa[*] [dim|{CLR['code_border']}](│)
33
+ [dim|{CLR['code_border']}](╰────────────────────────────────────────────────────╯)
34
+ [b|#FCFCFF]Documentation:[*]
35
+ [dim|{CLR['code_border']}](╭────────────────────────────────────────────────────╮)
36
+ [dim|{CLR['code_border']}](│) [#DADADD]For more information see the GitHub page. [dim|{CLR['code_border']}](│)
37
+ [dim|{CLR['code_border']}](│) [u|#8085FF](https://github.com/XulbuX/PythonLibraryXulbuX/wiki) [dim|{CLR['code_border']}](│)
38
+ [dim|{CLR['code_border']}](╰────────────────────────────────────────────────────╯)
39
+ [_]"""
40
+ )
41
+
42
+
43
+ def show_help() -> None:
44
+ print(HELP)
45
+ Console.pause_exit(pause=True, prompt=" [dim](Press any key to exit...)\n\n")
xulbux/console.py CHANGED
@@ -366,9 +366,12 @@ class Console:
366
366
  end: str = "\n",
367
367
  title_bg_color: Optional[Rgba | Hexa] = None,
368
368
  default_color: Optional[Rgba | Hexa] = None,
369
- _console_tabsize: int = 8,
369
+ tab_size: int = 8,
370
+ title_px: int = 1,
371
+ title_mx: int = 2,
370
372
  ) -> None:
371
- """Will print a formatted log message:
373
+ """Prints a nicely formatted log message.\n
374
+ -------------------------------------------------------------------------------------------
372
375
  - `title` -⠀the title of the log message (e.g. `DEBUG`, `WARN`, `FAIL`, etc.)
373
376
  - `prompt` -⠀the log message
374
377
  - `format_linebreaks` -⠀whether to format (indent after) the line breaks or not
@@ -376,38 +379,40 @@ class Console:
376
379
  - `end` -⠀something to print after the log is printed (e.g. `\\n`)
377
380
  - `title_bg_color` -⠀the background color of the `title`
378
381
  - `default_color` -⠀the default text color of the `prompt`
379
- - `_console_tabsize` -⠀the tab size of the console (default is 8)\n
380
- -----------------------------------------------------------------------------------
382
+ - `tab_size` -⠀the tab size used for the log (default is 8 like console tabs)
383
+ - `title_px` -⠀the horizontal padding (in chars) to the title (if `title_bg_color` is set)
384
+ - `title_mx` -⠀the horizontal margin (in chars) to the title\n
385
+ -------------------------------------------------------------------------------------------
381
386
  The log message can be formatted with special formatting codes. For more detailed
382
387
  information about formatting codes, see `format_codes` module documentation."""
388
+ has_title_bg = title_bg_color is not None and Color.is_valid(title_bg_color)
383
389
  title = "" if title is None else title.strip().upper()
384
- title_len, tab_len = len(title) + 4, _console_tabsize - ((len(title) + 4) % _console_tabsize)
385
- if title_bg_color is not None and Color.is_valid(title_bg_color):
386
- title_bg_color = Color.to_hexa(title_bg_color)
387
- title_color = Color.text_color_for_on_bg(title_bg_color)
388
- else:
389
- title_color = "_color" if title_bg_color is None else "#000"
390
+ title_fg = Color.text_color_for_on_bg(
391
+ Color.to_hexa(title_bg_color) # type: ignore[assignment]
392
+ ) if has_title_bg else "_color"
393
+ px, mx = (" " * title_px) if has_title_bg else "", " " * title_mx
394
+ tab = " " * (tab_size - 1 - ((len(mx) + (title_len := len(title) + 2 * len(px))) % tab_size))
390
395
  if format_linebreaks:
391
396
  clean_prompt, removals = FormatCodes.remove_formatting(str(prompt), get_removals=True, _ignore_linebreaks=True)
392
- prompt_lst = (String.split_count(l, Console.w - (title_len + tab_len)) for l in str(clean_prompt).splitlines())
397
+ prompt_lst = (
398
+ String.split_count(l, Console.w - (title_len + len(tab) + 2 * len(mx))) for l in str(clean_prompt).splitlines()
399
+ )
393
400
  prompt_lst = (
394
401
  item for lst in prompt_lst for item in ([""] if lst == [] else (lst if isinstance(lst, list) else [lst]))
395
402
  )
396
- prompt = f"\n{' ' * title_len}\t".join(
403
+ prompt = f"\n{mx}{' ' * title_len}{mx}{tab}".join(
397
404
  Console.__add_back_removed_parts(list(prompt_lst), cast(tuple[tuple[int, str], ...], removals))
398
405
  )
399
- else:
400
- prompt = str(prompt)
401
406
  if title == "":
402
407
  FormatCodes.print(
403
- f'{start} {f"[{default_color}]" if default_color else ""}{str(prompt)}[_]',
408
+ f'{start} {f"[{default_color}]" if default_color else ""}{prompt}[_]',
404
409
  default_color=default_color,
405
410
  end=end,
406
411
  )
407
412
  else:
408
413
  FormatCodes.print(
409
- f'{start} [bold][{title_color}]{f"[BG:{title_bg_color}]" if title_bg_color else ""} {title} [_]'
410
- + f'\t{f"[{default_color}]" if default_color else ""}{prompt}[_]',
414
+ f"{start}{mx}[bold][{title_fg}]{f'[BG:{title_bg_color}]' if title_bg_color else ''}{px}{title}{px}[_]{mx}"
415
+ + f"{tab}{f'[{default_color}]' if default_color else ''}{prompt}[_]",
411
416
  default_color=default_color,
412
417
  end=end,
413
418
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xulbux
3
- Version: 1.8.0
3
+ Version: 1.8.1
4
4
  Summary: A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler.
5
5
  Author-email: XulbuX <xulbux.real@gmail.com>
6
6
  Maintainer-email: XulbuX <xulbux.real@gmail.com>
@@ -1,7 +1,7 @@
1
- xulbux/__init__.py,sha256=ee9vPsQXG50BOKoVLqUmcClEs-94eYHN3572x0AC3BY,817
1
+ xulbux/__init__.py,sha256=FkJeare6GgT7xau1OcZVKoLk3uUOULFWdP2DYzOCW58,817
2
2
  xulbux/code.py,sha256=CLA3wh6mTvcXTlQgBeFaaLIBciHvXWqVM56rAtfO-JE,6102
3
3
  xulbux/color.py,sha256=XCB05xBSEz6-dpX9yVkMB2zTSdTH01MfUazJEthL_zM,49741
4
- xulbux/console.py,sha256=J--5Ma2H3-YPT21pT92J4mNgu-0h_vJJ8M1BLOKbHWc,42773
4
+ xulbux/console.py,sha256=U9t4Fd_ZGrdhTf8KMKJJqw12aijpur3b9J3rlEgntW4,43164
5
5
  xulbux/data.py,sha256=hB9JxrSC7_6kelJ_TwOaapNrlig-jiyNZS3YoiJX8F8,30884
6
6
  xulbux/env_path.py,sha256=HGOSffdIDubzczsXe6umyqotrzqhIW83QBkISAamXT8,4157
7
7
  xulbux/file.py,sha256=7pa0-WS_DpXq7HRB1fLS6Acd9CM-ozXPpNJvMqCW4fw,2624
@@ -11,8 +11,10 @@ xulbux/path.py,sha256=lLAEVZrW0TAwCewlONFVQcQ_8tVn9LTJZVOZpeGvE5s,7673
11
11
  xulbux/regex.py,sha256=_BtMHRDNcD9zF4SL87dQuUVZcYGfZx9H5YNSDiEtzm8,8059
12
12
  xulbux/string.py,sha256=QaTo0TQ9m_2USNgQNaVw5ivQt-A1E-e5x8OpIB3xIlY,5561
13
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,,
14
+ xulbux/base/consts.py,sha256=HwgI_Cr_U2QznezN17SP1j-gpyf3tsbu_KHMd8aKzyw,5918
15
+ xulbux/cli/help.py,sha256=QtyAqHEC_0p3qvLXdUBlpvjV9khPy70-po7CQOz1Fag,3314
16
+ xulbux-1.8.1.dist-info/METADATA,sha256=Z3S8mdtlmI85R3M3Ks38oUUnx4vzBn91_N3CJabSUIo,11041
17
+ xulbux-1.8.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ xulbux-1.8.1.dist-info/entry_points.txt,sha256=aYh89GfiBOB8vw2VPgC6rhBinhnJoAL1kig-3lq_zkg,58
19
+ xulbux-1.8.1.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
20
+ xulbux-1.8.1.dist-info/RECORD,,
File without changes