Skip to content

Commit be55296

Browse files
committed
update 1.8.1
1 parent 46e2ab9 commit be55296

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
# <br><b>Changelog</b><br>
1616

17+
## ... `v1.8.1`
18+
* renamed the param `_console_tabsize` form the method `Console.log()` to `tab_size`, and it will now just set the size for the log directly instead of specifying, what the console's tab size is
19+
* fixed several small bugs regarding the tabs and text wrapping inside `Console.log()`
20+
* added two new params to `Console.log()`:
21+
- <code>title_px: *int* = 1</code> the horizontal padding (*in chars*) to the title (*if* `title_bg_color` *is set*)
22+
- <code>title_mx: *int* = 2</code> the horizontal margin (*in chars*) to the title
23+
1724
## 28.08.2025 `v1.8.0`
1825
* new options for the param `find_args` from the method `Console.get_args()`:
1926
previously you could only input a dictionary with items like `"alias_name": ["-f", "--flag"]` that specify an arg's alias and the flags that correspond to it

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "xulbux"
7-
version = "1.8.0"
7+
version = "1.8.1"
88
authors = [{ name = "XulbuX", email = "xulbux.real@gmail.com" }]
99
maintainers = [{ name = "XulbuX", email = "xulbux.real@gmail.com" }]
1010
description = "A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler."

src/xulbux/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.8.0"
1+
__version__ = "1.8.1"
22

33
__author__ = "XulbuX"
44
__email__ = "xulbux.real@gmail.com"

src/xulbux/console.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,48 +366,53 @@ def log(
366366
end: str = "\n",
367367
title_bg_color: Optional[Rgba | Hexa] = None,
368368
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,
370372
) -> None:
371-
"""Will print a formatted log message:
373+
"""Prints a nicely formatted log message.\n
374+
-------------------------------------------------------------------------------------------
372375
- `title` -⠀the title of the log message (e.g. `DEBUG`, `WARN`, `FAIL`, etc.)
373376
- `prompt` -⠀the log message
374377
- `format_linebreaks` -⠀whether to format (indent after) the line breaks or not
375378
- `start` -⠀something to print before the log is printed
376379
- `end` -⠀something to print after the log is printed (e.g. `\\n`)
377380
- `title_bg_color` -⠀the background color of the `title`
378381
- `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+
-------------------------------------------------------------------------------------------
381386
The log message can be formatted with special formatting codes. For more detailed
382387
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)
383389
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))
390395
if format_linebreaks:
391396
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+
)
393400
prompt_lst = (
394401
item for lst in prompt_lst for item in ([""] if lst == [] else (lst if isinstance(lst, list) else [lst]))
395402
)
396-
prompt = f"\n{' ' * title_len}\t".join(
403+
prompt = f"\n{mx}{' ' * title_len}{mx}{tab}".join(
397404
Console.__add_back_removed_parts(list(prompt_lst), cast(tuple[tuple[int, str], ...], removals))
398405
)
399-
else:
400-
prompt = str(prompt)
401406
if title == "":
402407
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}[_]',
404409
default_color=default_color,
405410
end=end,
406411
)
407412
else:
408413
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}[_]",
411416
default_color=default_color,
412417
end=end,
413418
)

0 commit comments

Comments
 (0)