Skip to content

Commit

Permalink
Use pp from rich
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Nov 29, 2024
1 parent de9c3a2 commit f9bbbd4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/collective/pdbpp/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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():
Expand Down

0 comments on commit f9bbbd4

Please sign in to comment.