From 8b1f0e7e0a564827c626bea5681584ed5a475930 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 12 Aug 2020 21:21:10 +0100 Subject: [PATCH] simplify pretty --- docs/source/console.rst | 2 +- rich/pretty.py | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/source/console.rst b/docs/source/console.rst index ef96cd7a..dfc8ad60 100644 --- a/docs/source/console.rst +++ b/docs/source/console.rst @@ -112,7 +112,7 @@ Note that you generally don't need to think about cropping, as Rich will wrap te Justify / Alignment ------------------- -Both print and log support a ``justify`` argument which if set must be one of "default", "left", "right", "center", "full", or "ignore". If "left", any text printed (or logged) will be left aligned, if "right" text will be aligned to the right of the terminal, if "center" the text will be centered, and if "full" the text will be lined up with both the left and right edges of the terminal (like printed text in a book). +Both print and log support a ``justify`` argument which if set must be one of "default", "left", "right", "center", or "full". If "left", any text printed (or logged) will be left aligned, if "right" text will be aligned to the right of the terminal, if "center" the text will be centered, and if "full" the text will be lined up with both the left and right edges of the terminal (like printed text in a book). The default for ``justify`` is ``"default"`` which will generally look the same as ``"left"`` but with a subtle difference. Left justify will pad the right of the text with spaces, while a default justify will not. You will only notice the difference if you set a background color with the ``style`` argument. The following example demonstrates the difference:: diff --git a/rich/pretty.py b/rich/pretty.py index 5a8c8086..7f6f836d 100644 --- a/rich/pretty.py +++ b/rich/pretty.py @@ -26,15 +26,13 @@ if TYPE_CHECKING: # pragma: no cover def install( console: "Console" = None, - no_wrap: bool = False, - overflow: "OverflowMethod" = None, + overflow: "OverflowMethod" = "ignore", crop: bool = False, ) -> None: """Install automatic pretty printing in the Python REPL. Args: - console (Console, optional): Console instance or ``None`` to use global console. Defaults to None. - no_wrap (Optional[bool], optional): Don't wrap long lines. Defaults to False. + console (Console, optional): Console instance or ``None`` to use global console. Defaults to None. overflow (Optional[OverflowMethod], optional): Overflow method. Defaults to None. crop (Optional[bool], optional): Enable cropping of long lines. Defaults to False. """ @@ -48,9 +46,7 @@ def install( console.print( value if hasattr(value, "__rich_console__") or hasattr(value, "__rich__") - else pretty_repr( - value, max_width=console.width, no_wrap=no_wrap, overflow=overflow - ), + else pretty_repr(value, max_width=console.width, overflow=overflow), crop=crop, ) @@ -68,14 +64,12 @@ class Pretty: indent_size: int = 4, justify: "JustifyMethod" = None, overflow: "OverflowMethod" = None, - no_wrap: bool = None, ) -> None: self._object = _object self.highlighter = highlighter or NullHighlighter() self.indent_size = indent_size self.justify = justify self.overflow = overflow - self.no_wrap = no_wrap def __rich_console__( self, console: "Console", options: "ConsoleOptions" @@ -86,7 +80,6 @@ class Pretty: indent_size=self.indent_size, justify=self.justify or options.justify, overflow=self.overflow or options.overflow, - no_wrap=pick_bool(self.no_wrap, options.no_wrap, True), ) yield pretty_text