MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / ppretty

Method ppretty

cmd2/cmd2.py:1872–1920  ·  view source on GitHub ↗

Pretty print an object. This is a cmd2-compatible replacement for rich.pretty.pprint(). :param obj: object to pretty print :param file: file stream being written to or None for self.stdout. Defaults to None. :param indent_size: number of spaces

(
        self,
        obj: Any,
        *,
        file: IO[str] | None = None,
        indent_size: int = 4,
        indent_guides: bool = True,
        max_length: int | None = None,
        max_string: int | None = None,
        max_depth: int | None = None,
        expand_all: bool = False,
        end: str = "\n",
    )

Source from the content-addressed store, hash-verified

1870 )
1871
1872 def ppretty(
1873 self,
1874 obj: Any,
1875 *,
1876 file: IO[str] | None = None,
1877 indent_size: int = 4,
1878 indent_guides: bool = True,
1879 max_length: int | None = None,
1880 max_string: int | None = None,
1881 max_depth: int | None = None,
1882 expand_all: bool = False,
1883 end: str = "\n",
1884 ) -> None:
1885 """Pretty print an object.
1886
1887 This is a cmd2-compatible replacement for rich.pretty.pprint().
1888
1889 :param obj: object to pretty print
1890 :param file: file stream being written to or None for self.stdout.
1891 Defaults to None.
1892 :param indent_size: number of spaces in indent. Defaults to 4.
1893 :param indent_guides: enable indentation guides. Defaults to True.
1894 :param max_length: maximum length of containers before abbreviating, or None for no abbreviation.
1895 Defaults to None.
1896 :param max_string: maximum length of strings before truncating, or None to disable. Defaults to None.
1897 :param max_depth: maximum depth for nested data structures, or None for unlimited depth. Defaults to None.
1898 :param expand_all: Expand all containers. Defaults to False.
1899 :param end: string to write at end of printed text. Defaults to a newline.
1900 """
1901 # The overflow and soft_wrap values match those in rich.pretty.pprint().
1902 # This ensures long strings are neither truncated with ellipses nor broken
1903 # up by injected newlines.
1904 pretty_obj = Pretty(
1905 obj,
1906 indent_size=indent_size,
1907 indent_guides=indent_guides,
1908 max_length=max_length,
1909 max_string=max_string,
1910 max_depth=max_depth,
1911 expand_all=expand_all,
1912 overflow="ignore",
1913 )
1914
1915 self.print_to(
1916 file or self.stdout,
1917 pretty_obj,
1918 soft_wrap=True,
1919 end=end,
1920 )
1921
1922 def get_bottom_toolbar(self) -> list[str | tuple[str, str]] | None:
1923 """Get the bottom toolbar content.

Callers 2

test_pprettyFunction · 0.80
do_prettyMethod · 0.80

Calls 1

print_toMethod · 0.95

Tested by 1

test_pprettyFunction · 0.64