mirror of https://github.com/Textualize/rich.git
clean up documentation and remove un-needed re-shaping
This commit is contained in:
parent
1f8d565579
commit
c4e9241c17
|
@ -1,6 +1,5 @@
|
||||||
.. _live:
|
.. _live:
|
||||||
|
|
||||||
|
|
||||||
Live Display
|
Live Display
|
||||||
============
|
============
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ To see some live display examples, try this from the command line::
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Make sure your terminal is tall enough or you may see it print "Terminal too small"
|
If you see ellipsis "...", this indicates that the terminal is not tall enough to show the full table.
|
||||||
|
|
||||||
Basic Usage
|
Basic Usage
|
||||||
-----------
|
-----------
|
||||||
|
@ -92,7 +91,6 @@ You can also make the live display disappear on exit by setting ``transient=True
|
||||||
with Live(transient=True) as live:
|
with Live(transient=True) as live:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
Auto refresh
|
Auto refresh
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -102,21 +100,19 @@ You should set this to something lower than 4 if you know your updates will not
|
||||||
You might want to disable auto-refresh entirely if your updates are not very frequent, which you can do by setting ``auto_refresh=False`` on the constructor.
|
You might want to disable auto-refresh entirely if your updates are not very frequent, which you can do by setting ``auto_refresh=False`` on the constructor.
|
||||||
If you disable auto-refresh you will need to call :meth:`~rich.live.Live.refresh` manually or :meth:`~rich.live.Live.update` with ``refresh=True``.
|
If you disable auto-refresh you will need to call :meth:`~rich.live.Live.refresh` manually or :meth:`~rich.live.Live.update` with ``refresh=True``.
|
||||||
|
|
||||||
Hide "Terminal Too Small" Warning
|
Vertical Overflow
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
By default, the live display will not render if the renderable is too tall for the console and instead will render a warning line "Terminal Too Small".
|
By default, the live display will display ellipsis if the renderable is too large for the terminal. You can adjust this by setting the
|
||||||
This is because the console cannot properly clear a renderable if it is too large (limitation on terminals). You can disable this by setting ``hide_overflow=False`` on the constructor.
|
``vertical_overflow`` argument on the :class:`~rich.live.Live` constructor.
|
||||||
|
|
||||||
You may want to disable this feature if:
|
|
||||||
|
|
||||||
1. You want to always see the live display and also do not mind that it will fill-up with previous renderings.
|
|
||||||
2. If you need the display to render as fast as possible. (This check performs a pre-rendering of the renderable which may be costly)
|
|
||||||
|
|
||||||
|
- crop: Show renderable up to the terminal height. The rest is hidden
|
||||||
|
- ellipsis: Similar to crop except last line shows "...". This is the default behavior.
|
||||||
|
- visible: Will allow the whole renderable to be shown. Note that the display cannot be properly cleared in this mode.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Once the live display stops, even if the display is too small it will render the last frame since it doesn't have to clear it.
|
Once the live display stops on a non-transient renderable, the last frame will render as **visible** since it doesn't have to be cleared clear it.
|
||||||
|
|
||||||
Complex Renders
|
Complex Renders
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
13
rich/live.py
13
rich/live.py
|
@ -18,6 +18,7 @@ from .control import Control
|
||||||
from .jupyter import JupyterMixin
|
from .jupyter import JupyterMixin
|
||||||
from .progress import _FileProxy
|
from .progress import _FileProxy
|
||||||
from .segment import Segment
|
from .segment import Segment
|
||||||
|
from .style import Style
|
||||||
|
|
||||||
VerticalOverflowMethod = Literal["crop", "ellipsis", "visible"]
|
VerticalOverflowMethod = Literal["crop", "ellipsis", "visible"]
|
||||||
|
|
||||||
|
@ -73,18 +74,18 @@ class _LiveRender:
|
||||||
lines = console.render_lines(self.renderable, options, pad=False)
|
lines = console.render_lines(self.renderable, options, pad=False)
|
||||||
|
|
||||||
shape = Segment.get_shape(lines)
|
shape = Segment.get_shape(lines)
|
||||||
width, height = shape
|
_, height = shape
|
||||||
if shape[1] > console.size.height:
|
if height > console.size.height:
|
||||||
if self.vertical_overflow == "crop":
|
if self.vertical_overflow == "crop":
|
||||||
lines = lines[: console.size.height]
|
lines = lines[: console.size.height]
|
||||||
shape = Segment.get_shape(lines)
|
shape = Segment.get_shape(lines)
|
||||||
elif self.vertical_overflow == "ellipsis":
|
elif self.vertical_overflow == "ellipsis":
|
||||||
lines = lines[: (console.size.height - 1)] + [[Segment("...")]]
|
lines = lines[: (console.size.height - 1)] + [
|
||||||
|
[Segment("...", style=Style(bold=True))]
|
||||||
|
]
|
||||||
shape = Segment.get_shape(lines)
|
shape = Segment.get_shape(lines)
|
||||||
self.shape = shape
|
self.shape = shape
|
||||||
|
|
||||||
width, height = self.shape
|
|
||||||
lines = Segment.set_shape(lines, width, height)
|
|
||||||
for last, line in loop_last(lines):
|
for last, line in loop_last(lines):
|
||||||
yield from line
|
yield from line
|
||||||
if not last:
|
if not last:
|
||||||
|
@ -115,7 +116,7 @@ class Live(JupyterMixin, RenderHook):
|
||||||
transient: bool = False,
|
transient: bool = False,
|
||||||
redirect_stdout: bool = True,
|
redirect_stdout: bool = True,
|
||||||
redirect_stderr: bool = True,
|
redirect_stderr: bool = True,
|
||||||
vertical_overflow: VerticalOverflowMethod = "crop",
|
vertical_overflow: VerticalOverflowMethod = "ellipsis",
|
||||||
) -> None:
|
) -> None:
|
||||||
assert refresh_per_second > 0, "refresh_per_second must be > 0"
|
assert refresh_per_second > 0, "refresh_per_second must be > 0"
|
||||||
self.console = console if console is not None else get_console()
|
self.console = console if console is not None else get_console()
|
||||||
|
|
Loading…
Reference in New Issue