Metadata-Version: 2.4
Name: pycolorutils
Version: 1.2.7
Summary: A set of useful utilities for Python
Author-email: Pecacheu <3608878+Pecacheu@users.noreply.github.com>
License-Expression: GPL-3.0
Project-URL: Homepage, https://github.com/Pecacheu/PyColor
Project-URL: Issues, https://github.com/Pecacheu/PyColor/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# PyColorUtils

A set of useful utilities for Python. Same vibe as [C-Utils](https://github.com/Pecacheu/C-Utils) and [Utils.js](https://github.com/Pecacheu/Utils.js).

Install via `pip install pycolorutils`

# Color

## Color Preset Strings
Format strings for console printing.
- `C.Rst` Reset
- `C.Br` Bright
- `C.Di` Dim
- `C.Un` Underscore
- `C.Bl` Blink
- `C.Rv` Reverse
- `C.Blk` Black
- `C.Red` Red
- `C.Grn` Green
- `C.Ylo` Yellow
- `C.Blu` Blue
- `C.Mag` Magenta
- `C.Cya` Cyan
- `C.Whi` White
- `C.BgBlk` BgBlack
- `C.BgRed` BgRed
- `C.BgGrn` BgGreen
- `C.BgYlo` BgYellow
- `C.BgBlu` BgBlue
- `C.BgMag` BgMagenta
- `C.BgCya` BgCyan
- `C.BgWhi` BgWhite

## Logging & Errors
- `msg(*m)` Like `print()` but automatically appends `C.Rst` to the end.
- `err(e: Any, ex: int=0)` Prints an error to the console (stderr) in red. If `ex` is non-zero, also exits with exit code.
- `warn(w: Any)` Prints a warning to the console (stderr) in yellow.
- `eInfo(e: Exception)` Returns a human-readable string for the exception.
- `onMsg = callable(m: str)` If defined, redirects output from `msg()`
- `onErr = callable(e: str)` If defined, redirects output from `err()`

## Main & Exit
- `execMain(main: callable)` Wraps `main` so that when it ends, all atexit functions are run, even if an exception or interrupt occurs.
- `atexit(f: callable)` Run `f` before exit. More reliable than builtin `atexit` module if `execMain()` is used, falls back on atexit otherwise.
- `exit(ex: int=0)` Overrides builtin `exit` to exit cleanly, with optional exit code.

## Misc
- `getDictKey(d: dict, val: Any)` Returns the first key in `d` whose value is `val`. Raises **ValueError** if not found.

# UUID
Python port of the [64-bit ChuID UUID format](https://github.com/Pecacheu/Utils.js?tab=readme-ov-file#uuid). ChuID outputs as a compact, 11 character Base64 string. It's made for situations where a longer 128-bit format like UUIDv4 is overkill.

Format: `<U8 Uptime><U8 Magic><U8 CryptoRand><U8 Counter><U32 Date>`

```py
from uuid import UUID

#Current date, magic value 15
id = UUID.genUUID(None, 15)

print(id.id, f"String: {id}\n",
	id.date(), id.magic())
```

## Methods
- `UUID(id)` Construct ID from bytes or str
- `UUID.genUUID([date[, magic]])` Generate new random UUID w/ optional date and magic

# Reader
*TODO Detailed help coming soon!*

# FancyTable
Render a fancy table in the console w/ colored borders and a header row.
- `table(title: str, width: int, colNames: list[str], data: list[list[str]], color: str=None)`
