From d44340ab9d4a24806ca1b8657bd1361d3c65ed04 Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Thu, 11 Aug 2022 16:14:04 -0400 Subject: [PATCH] time to get RICH --- poetry.lock | 48 +++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + src/cli.py | 20 +++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 7af1e9b..d341e40 100644 --- a/poetry.lock +++ b/poetry.lock @@ -139,6 +139,17 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +[[package]] +name = "commonmark" +version = "0.9.1" +description = "Python parser for the CommonMark Markdown spec" +category = "main" +optional = false +python-versions = "*" + +[package.extras] +test = ["hypothesis (==3.55.3)", "flake8 (==3.7.8)"] + [[package]] name = "crashtest" version = "0.3.1" @@ -422,6 +433,14 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +[[package]] +name = "pygments" +version = "2.12.0" +description = "Pygments is a syntax highlighting package written in Python." +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "pylev" version = "1.4.0" @@ -492,6 +511,21 @@ idna = {version = "*", optional = true, markers = "extra == \"idna2008\""} [package.extras] idna2008 = ["idna"] +[[package]] +name = "rich" +version = "12.5.1" +description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" +category = "main" +optional = false +python-versions = ">=3.6.3,<4.0.0" + +[package.dependencies] +commonmark = ">=0.9.0,<0.10.0" +pygments = ">=2.6.0,<3.0.0" + +[package.extras] +jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"] + [[package]] name = "secretstorage" version = "3.3.2" @@ -597,7 +631,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "ccfdeb63811daaa93297ab75bfd661b68b7f04683c8310f0d60783ec56a577cc" +content-hash = "996999ee56b557d60dacce8564ac786e41fea036aabedbe3637ca415b6ee959f" [metadata.files] anyio = [] @@ -614,6 +648,10 @@ click = [ ] clikit = [] colorama = [] +commonmark = [ + {file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"}, + {file = "commonmark-0.9.1.tar.gz", hash = "sha256:452f9dc859be7f06631ddcb328b6919c67984aca654e5fefb3914d54691aed60"}, +] crashtest = [] cryptography = [] distlib = [] @@ -665,6 +703,10 @@ pycparser = [ {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"}, {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"}, ] +pygments = [ + {file = "Pygments-2.12.0-py3-none-any.whl", hash = "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519"}, + {file = "Pygments-2.12.0.tar.gz", hash = "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb"}, +] pylev = [] pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, @@ -674,6 +716,10 @@ pywin32-ctypes = [] requests = [] requests-toolbelt = [] rfc3986 = [] +rich = [ + {file = "rich-12.5.1-py3-none-any.whl", hash = "sha256:2eb4e6894cde1e017976d2975ac210ef515d7548bc595ba20e195fb9628acdeb"}, + {file = "rich-12.5.1.tar.gz", hash = "sha256:63a5c5ce3673d3d5fbbf23cd87e11ab84b6b451436f1b7f19ec54b6bc36ed7ca"}, +] secretstorage = [] shellingham = [] shiv = [] diff --git a/pyproject.toml b/pyproject.toml index d84d744..8b2352d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ python = "^3.10" shiv = "^1.0.1" httpx = "^0.23.0" click = "^8.1.3" +rich = "^12.5.1" [tool.poetry.dev-dependencies] poetry = "^1.1.14" diff --git a/src/cli.py b/src/cli.py index 8cacd94..9de98c2 100644 --- a/src/cli.py +++ b/src/cli.py @@ -6,6 +6,8 @@ import uuid import click import httpx +from rich import pretty +from rich import print as rprint from shiv.bootstrap import current_zipfile import src @@ -22,8 +24,24 @@ from src.art import BANNERS def main(ctx): """Launch a utility or drop into a command line REPL if no command is given.""" if ctx.invoked_subcommand is None: + def print_wrapper(*args, **kwargs): + # I know this is dumb. + # https://github.com/Textualize/rich/discussions/2462 + if "crop" in kwargs: + del kwargs["crop"] + rprint(*args, **kwargs) + banner = random.choice(BANNERS) - code.interact(banner=banner, local=globals()) + + # source of code.interact, just expanded to fit Rich in there + console = code.InteractiveConsole(globals()) + console.print = print_wrapper + pretty.install(console) # type: ignore + try: + import readline + except ImportError: + pass + console.interact(banner, None) sys.exit()