mirror of https://github.com/Textualize/rich.git
words
This commit is contained in:
parent
63ae6d3acd
commit
f7c3c98e66
|
@ -1,7 +1,7 @@
|
|||
Pretty
|
||||
======
|
||||
|
||||
In addition to syntax highlighting, Rich will format (i.e. *pretty print*) any containers such as lists, dicts, and sets.
|
||||
In addition to syntax highlighting, Rich will format (i.e. *pretty print*) containers such as lists, dicts, and sets.
|
||||
|
||||
Run the following command to see an example of pretty printed output::
|
||||
|
||||
|
@ -32,7 +32,7 @@ Rich is quite conservative about expanding data structures and will try to fit a
|
|||
Truncating pretty output
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Very long data structures can be difficult to read and you may find yourself scrolling through multiple pages to find the output you are interested in. Rich can truncate containers and long strings to give you an overview without swamping your terminal.
|
||||
Very long data structures can be difficult to read and you may find yourself scrolling through multiple pages in the terminal to find the data you are interested in. Rich can truncate containers and long strings to give you an overview without swamping your terminal.
|
||||
|
||||
|
||||
If you set the ``max_length`` argument to an integer, Rich will truncate containers with more than the given number of elements. If data is truncated, Rich will display an ellipsis ``...`` and the number of elements not shown.
|
||||
|
@ -62,8 +62,8 @@ The following example displays pretty printed data within a simple panel::
|
|||
|
||||
There are a large number of options to tweak the pretty formatting, See the :class:`~rich.pretty.Pretty` reference for details.
|
||||
|
||||
Rich Repr
|
||||
---------
|
||||
Rich Repr Protocol
|
||||
------------------
|
||||
|
||||
Rich is able to syntax highlight any output, but the formatting is restricted to builtin containers, dataclasses, and other objects Rich knows about, such as objects generated by the `attrs <https://www.attrs.org/en/stable/>`_ library. To add Rich formatting capabilities to custom objects, you can implement the *rich repr protocol*.
|
||||
|
||||
|
@ -120,7 +120,7 @@ Now if we print the same object with Rich we would see the following::
|
|||
'dodo': Bird('dodo', eats=['fruit'], fly=False, extinct=True)
|
||||
}
|
||||
|
||||
The default arguments have been omitted, and the output has been formatted nicely. If we have less room in the terminal, or our objects are part of a deeply nested data structure the output is still quite readable::
|
||||
The default arguments have been omitted, and the output has been formatted nicely. The output remains readable even if we have less room in the terminal, or our objects are part of a deeply nested data structure::
|
||||
|
||||
{
|
||||
'gull': Bird(
|
||||
|
@ -145,7 +145,7 @@ The default arguments have been omitted, and the output has been formatted nicel
|
|||
)
|
||||
}
|
||||
|
||||
You can add a ``__rich_repr__`` method to any class to enable the Rich formatting This method should return an iterable of tuples. You could return a list of tuples, but it's easier to express with the ``yield`` keywords, making it a *generator*.
|
||||
You can add a ``__rich_repr__`` method to any class to enable the Rich formatting. This method should return an iterable of tuples. You could return a list of tuples, but it's easier to express with the ``yield`` keywords, making it a *generator*.
|
||||
|
||||
Each tuple specifies an element in the output.
|
||||
|
||||
|
|
Loading…
Reference in New Issue