From f9bbbd4d080ef2507eb93e6abaef3bff3f59a5d7 Mon Sep 17 00:00:00 2001 From: ale-rt Date: Fri, 29 Nov 2024 17:02:21 +0100 Subject: [PATCH] Use pp from rich --- src/collective/pdbpp/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/collective/pdbpp/__init__.py b/src/collective/pdbpp/__init__.py index 9f7e8ab..504b34a 100644 --- a/src/collective/pdbpp/__init__.py +++ b/src/collective/pdbpp/__init__.py @@ -1,6 +1,7 @@ """Init and utils.""" from AccessControl import Unauthorized +from pdb import Pdb from plone import api from Products.Five import BrowserView from rich import inspect @@ -15,6 +16,20 @@ def initialize(context): pass +def _do_pp(self, arg): + """Override the pp (pretty-print) command to use rich.""" + try: + # Evaluate the argument in the current debugging context + obj = self._getval(arg) + # Use rich's pprint to display the object + pretty.pprint(obj, expand_all=True) + except Exception as e: + print(f"[red]Error:[/red] {e}") # noqa E231 + + +Pdb.do_pp = _do_pp + + class PdbView(BrowserView): def __call__(self): if not api.env.debug_mode():