Repository: Textualize/rich

Issue:
[REQUEST] Add `max_depth` as a parameter to `install()`
**How would you improve Rich?**

Currently `rich.pretty.install()` accepts most of the parameters allowed by `rich.pretty.pprint()`, but it doesn't have `max_depth`. I would add this parameter to `install()`.

**What problem does it solve for you?**

I would like to use the rich install hook, but also to customize the pretty printing behaviour, specifically the `max_depth` argument to simplify the result presentation. It isn't trivial to implement this in user code, because the `install()` function is actually quite complex, and difficult to modify.



Discussion:
Actually, is there a chance we could just forward all the kwargs from `install` to the `Pretty` constructor or `_ipy_display_hook`? It seems like it would be more maintainable that way.

Resolving patch:
diff --git a/rich/pretty.py b/rich/pretty.py
--- a/rich/pretty.py
+++ b/rich/pretty.py
@@ -120,6 +120,7 @@ def _ipy_display_hook(
     indent_guides: bool = False,
     max_length: Optional[int] = None,
     max_string: Optional[int] = None,
+    max_depth: Optional[int] = None,
     expand_all: bool = False,
 ) -> None:
     # needed here to prevent circular import:
@@ -177,6 +178,7 @@ def _ipy_display_hook(
             indent_guides=indent_guides,
             max_length=max_length,
             max_string=max_string,
+            max_depth=max_depth,
             expand_all=expand_all,
             margin=12,
         ),
@@ -202,6 +204,7 @@ def install(
     indent_guides: bool = False,
     max_length: Optional[int] = None,
     max_string: Optional[int] = None,
+    max_depth: Optional[int] = None,
     expand_all: bool = False,
 ) -> None:
     """Install automatic pretty printing in the Python REPL.
@@ -214,6 +217,7 @@ def install(
         max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
             Defaults to None.
         max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
+        max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None.
         expand_all (bool, optional): Expand all containers. Defaults to False.
         max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
     """
@@ -236,6 +240,7 @@ def display_hook(value: Any) -> None:
                     indent_guides=indent_guides,
                     max_length=max_length,
                     max_string=max_string,
+                    max_depth=max_depth,
                     expand_all=expand_all,
                 ),
                 crop=crop,
@@ -258,6 +263,7 @@ def __call__(self, value: Any) -> Any:
                         indent_guides=indent_guides,
                         max_length=max_length,
                         max_string=max_string,
+                        max_depth=max_depth,
                         expand_all=expand_all,
                     )
                 else:


Test patch:
diff --git a/tests/test_pretty.py b/tests/test_pretty.py
--- a/tests/test_pretty.py
+++ b/tests/test_pretty.py
@@ -51,6 +51,15 @@ def test_install():
     assert sys.displayhook is not dh
 
 
+def test_install_max_depth():
+    console = Console(file=io.StringIO())
+    dh = sys.displayhook
+    install(console, max_depth=1)
+    sys.displayhook({"foo": {"bar": True}})
+    assert console.file.getvalue() == "{'foo': ...}\n"
+    assert sys.displayhook is not dh
+
+
 def test_ipy_display_hook__repr_html():
     console = Console(file=io.StringIO(), force_jupyter=True)