live refactor

This commit is contained in:
Will McGugan 2021-02-06 11:49:54 +00:00
parent 0a54346bda
commit 122b8131bb
24 changed files with 412 additions and 299 deletions

View file

@ -306,6 +306,13 @@ If Rich detects that it is not writing to a terminal it will strip control codes
Letting Rich auto-detect terminals is useful as it will write plain text when you pipe output to a file or other application.
Interactive mode
~~~~~~~~~~~~~~~~
Rich will remove animations such as progress bars and status indicators when not writing to a terminal as you probably don't want to write these out to a text file (for example). You can override this behavior by setting the ``force_interactive`` argument on the constructor. Set it to True to enable animations or False to disable them.
.. note::
Some CI systems support ANSI color and style but not anything that moves the cursor or selectively refreshes parts of the terminal. For these you might want to set ``force_terminal`` to ``True`` and ``force_interactve`` to ``False``.
Environment variables
---------------------

View file

@ -3,9 +3,9 @@
Live Display
============
Rich can display continiuously updated information for any renderable.
Progress bars and status indicators use a *live* display to animate parts of the terminal. You can build custom live displays with the :class:`~rich.live.Live` class.
To see some live display examples, try this from the command line::
For a demonstration of a live display, running the following command:
python -m rich.live
@ -21,7 +21,7 @@ The basic usage can be split into two use cases.
1. Same Renderable
~~~~~~~~~~~~~~~~~~
When keeping the same renderable, you simply pass the :class:`~rich.console.RenderableType` you would like to see updating and provide
When keeping the same renderable, pass the :class:`~rich.console.RenderableType` you would like to see updating and provide
a ``refresh_per_second`` parameter. The Live :class:`~rich.live.Live` will automatically update the console at the provided refresh rate.
@ -47,8 +47,8 @@ a ``refresh_per_second`` parameter. The Live :class:`~rich.live.Live` will autom
2. New Renderable
~~~~~~~~~~~~~~~~~
You can also provide constant new renderable to :class:`~rich.live.Live` using the :meth:`~rich.live.Live.update` function. This allows you to
completely change what is rendered live.
You can also provide a new renderable to :class:`~rich.live.Live` using the :meth:`~rich.live.Live.update` function. This allows you to
completely change the live display.
**Example**::
@ -163,6 +163,15 @@ Redirecting stdout / stderr
To avoid breaking the live display visuals, Rich will redirect ``stdout`` and ``stderr`` so that you can use the builtin ``print`` statement.
This feature is enabled by default, but you can disable by setting ``redirect_stdout`` or ``redirect_stderr`` to ``False``.
Nesting Lives
-------------
Note that only a single live context may be active at any one time. The following will raise a :class:`~rich.errors.LiveError` because status also uses Live::
with Live(table, console=console):
with console.status("working"): # Will not work
do_work()
Examples
--------

View file

@ -162,7 +162,13 @@ If the :class:`~rich.progress.Progress` class doesn't offer exactly what you nee
def get_renderables(self):
yield Panel(self.make_tasks_table(self.tasks))
Multiple Progress
-----------------
You can't have different columns per task with a single Progress instance. However, you can have as many Progress instance as you like in a :ref:`live`. See `live_progress.py <https://github.com/willmcgugan/rich/blob/master/examples/live_progress.py>`_ for an example of using mutiple Progress instances.
Example
-------
See `downloader.py <https://github.com/willmcgugan/rich/blob/master/examples/downloader.py>`_ for a realistic application of a progress display. This script can download multiple concurrent files with a progress bar, transfer speed and file size.