rich/docs/source/panel.rst

25 lines
1.1 KiB
ReStructuredText
Raw Normal View History

2020-03-08 18:34:56 +00:00
Panel
=====
2020-09-11 15:47:10 +00:00
To draw a border around text or other renderable, construct a :class:`~rich.panel.Panel` with the renderable as the first positional argument. Here's an example::
2020-03-08 18:34:56 +00:00
from rich import print
from rich.panel import Panel
print(Panel("Hello, [red]World!"))
2020-07-22 15:18:35 +00:00
You can change the style of the panel by setting the ``box`` argument to the Panel constructor. See :ref:`appendix_box` for a list of available box styles.
2020-08-01 12:00:24 +00:00
Panels will extend to the full width of the terminal. You can make panel *fit* the content by setting ``expand=False`` on the constructor, or by creating the Panel with :meth:`~rich.panel.Panel.fit`. For example::
2020-07-22 15:18:35 +00:00
from rich import print
from rich.panel import Panel
print(Panel.fit("Hello, [red]World!"))
2021-08-23 17:10:37 +00:00
The Panel constructor accepts a ``title`` argument which will draw a title on the top of the panel, as well as a ``subtitle`` argument which will draw a subtitle on the bottom of the panel::
2020-07-22 15:18:35 +00:00
from rich import print
from rich.panel import Panel
2021-08-23 17:10:37 +00:00
print(Panel("Hello, [red]World!", title="Welcome", subtitle="Thank you"))
2020-07-22 15:18:35 +00:00
2020-08-01 12:00:24 +00:00
See :class:`~rich.panel.Panel` for details how to customize Panels.