diff --git a/laser_prynter/pp.py b/laser_prynter/pp.py index 69e9f6b..e85dc74 100644 --- a/laser_prynter/pp.py +++ b/laser_prynter/pp.py @@ -9,7 +9,7 @@ from pygments import highlight, console from pygments.lexers import JsonLexer from pygments.formatters import Terminal256Formatter -from pygments.styles import get_style_by_name +from pygments.styles import get_style_by_name, get_all_styles STYLES = ( 'dracula', 'fruity', 'gruvbox-dark', 'gruvbox-light', 'lightbulb', 'material', 'native', @@ -63,7 +63,7 @@ def _json_default(obj: object) -> Any: elif hasattr(obj, '__dict__'): return obj.__dict__ # class return str(obj) -def ppd(d_obj: Any, indent: int|None=2, style: str|None='dracula', random_style: bool=False, **kwargs: Any) -> None: +def ppd(d_obj: Any, indent: int|None=None, style: str|None='dracula', random_style: bool=False, **kwargs: Any) -> None: 'pretty-print a dict' d = _normalise(d_obj) # convert any namedtuples to dicts @@ -85,6 +85,10 @@ def ppd(d_obj: Any, indent: int|None=2, style: str|None='dracula', random_style: **kwargs, ) +def random_style() -> str: + 'return a random style name' + return random.choice(STYLES) + def ppj(j: str, indent: int|None=None, style: str='dracula', random_style: bool=False, **kwargs: Any) -> None: 'pretty-print a JSON string' ppd(_normalise(json.loads(j)), indent=indent, style=style, random_style=random_style) @@ -99,9 +103,15 @@ def pps(s: str, style: str='yellow', random_style: bool=False) -> None: 'pretty-print a string' _print(ps(s, style=style, random_style=random_style)) -def demo(**kwargs: Any) -> None: +def demo(all_styles: bool=False, **kwargs: Any) -> None: 'demonstrate pretty-printing colours' + print('selected styles:') for s in STYLES: - ppd({'message': {'Hello': 'World', 'The answer is': 42}, 'style': s}, style=s, indent=None, **kwargs) + ppd({'message': {'Hello': 'World', 'The answer is': 42}, 'style': s}, style=s, **kwargs) + + if all_styles: + print('\nall other styles:') + for s in set(get_all_styles()) - set(STYLES): + ppd({'message': {'Hello': 'World', 'The answer is': 42}, 'style': s}, style=s, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index ab86dc6..d6d6274 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "laser-prynter" -version = "0.8.0" +version = "0.9.0" authors = [{ name = "tmck-code", email = "tmck01@gmail.com" }] description = "terminal/cli/python helpers for colour and pretty-printing" readme = "README.md" diff --git a/uv.lock b/uv.lock index 6f62a25..694a35a 100644 --- a/uv.lock +++ b/uv.lock @@ -4,7 +4,7 @@ requires-python = ">=3.12" [[package]] name = "laser-prynter" -version = "0.8.0" +version = "0.9.0" source = { virtual = "." } dependencies = [ { name = "pygments" },