diff --git a/README.md b/README.md index 1b80502..528fc60 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,11 @@ pip install --upgrade xulbux ## CLI Commands When the library is installed, the following commands are available in the console: -| Command | Description | -| :------------ | :--------------------------------------- | -| `xulbux-help` | shows some information about the library | + +| Command | Description | +| :------------ | :--------------------------------------------------------------- | +| `xulbux-help` | Show some information about the library. | +| `xulbux-fc` | Parse and render a string's format codes as ANSI console output. |
diff --git a/pyproject.toml b/pyproject.toml index 037b4e0..5aef643 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ build-backend = "setuptools.build_meta" [project] name = "xulbux" -version = "1.9.6" +version = "1.9.7" description = "A Python library to simplify common programming tasks." readme = "README.md" authors = [{ name = "XulbuX", email = "xulbux.real@gmail.com" }] @@ -117,6 +117,7 @@ keywords = [ [project.scripts] xulbux-help = "xulbux.cli.help:show_help" +xulbux-fc = "xulbux.cli.tools:render_format_codes" [tool.flake8] max-complexity = 12 diff --git a/src/xulbux/__init__.py b/src/xulbux/__init__.py index 16e5bfd..6c19cbe 100644 --- a/src/xulbux/__init__.py +++ b/src/xulbux/__init__.py @@ -1,5 +1,5 @@ __package_name__ = "xulbux" -__version__ = "1.9.6" +__version__ = "1.9.7" __description__ = "A Python library to simplify common programming tasks." __status__ = "Production/Stable" diff --git a/src/xulbux/cli/tools.py b/src/xulbux/cli/tools.py new file mode 100644 index 0000000..39a7dd4 --- /dev/null +++ b/src/xulbux/cli/tools.py @@ -0,0 +1,24 @@ +from ..format_codes import FormatCodes +from ..console import Console + + +def render_format_codes(): + args = Console.get_args({ "input": "before" }) + + if not args.input.values: + FormatCodes.print( + "\n[_|i|dim]Provide a string to parse and render\n" + "it's format codes as ANSI console output.[_]\n" + ) + + else: + ansi = FormatCodes.to_ansi("".join(args.input.values)) + ansi_escaped = FormatCodes.escape_ansi(ansi) + ansi_stripped = FormatCodes.remove_ansi(ansi) + + print(f"\n{ansi}\n") + + if len(ansi) != len(ansi_stripped): + FormatCodes.print(f"[_|i|dim]{ansi_escaped}[_]\n") + else: + FormatCodes.print("[_|i|dim](The provided string doesn't contain any valid format codes.)\n")