mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
docs
This commit is contained in:
parent
dc3998a821
commit
6b9adfa9c2
3 changed files with 9 additions and 12 deletions
|
@ -261,18 +261,15 @@ For examples of the html output generated by Rich Console, see :ref:`appendix-co
|
|||
Exporting SVGs
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
When using :meth:`~rich.console.Console.export_svg` or :meth:`~rich.console.Console.save_svg`, the width of the generated SVG will
|
||||
match the width (in terms of character cells) of your terminal window. The height of the exported SVG will scale automatically to accommodate the console output.
|
||||
When using :meth:`~rich.console.Console.export_svg` or :meth:`~rich.console.Console.save_svg`, the width of the SVG will match the width of your terminal window (in terms of characters), while the height will scale automatically to accommodate the console output.
|
||||
|
||||
The generated SVG can be viewed inside any web browser, and can be included on a webpage either by directly including the SVG markup
|
||||
or by referencing the file itself using an ``<img>`` tag. For finer control over the dimensions, you'll have to use an ``<img>`` tag.
|
||||
You can open the SVG in a web browser. You can also insert it in to a webpage with an ``<img>`` tag or by copying the markup in to your HTML.
|
||||
|
||||
The image below shows an example of an SVG exported by Rich.
|
||||
|
||||
.. image:: ../images/svg_export.svg
|
||||
|
||||
You can customise the theme used during SVG export by importing the desired theme from the :mod:`rich.terminal_theme` module and passing it to
|
||||
:meth:`~rich.console.Console.export_svg` or :meth:`~rich.console.Console.save_svg` via the ``theme`` parameter::
|
||||
You can customize the theme used during SVG export by importing the desired theme from the :mod:`rich.terminal_theme` module and passing it to :meth:`~rich.console.Console.export_svg` or :meth:`~rich.console.Console.save_svg` via the ``theme`` parameter::
|
||||
|
||||
|
||||
from rich.console import Console
|
||||
|
@ -281,8 +278,7 @@ You can customise the theme used during SVG export by importing the desired them
|
|||
console = Console(record=True)
|
||||
console.save_svg("example.svg", theme=MONOKAI)
|
||||
|
||||
Alternatively, you can create your own theme by constructing a :class:`rich.terminal_theme.TerminalTheme` instance
|
||||
yourself and passing that in.
|
||||
Alternatively, you can create a them of your own by constructing a :class:`rich.terminal_theme.TerminalTheme` instance yourself and passing that in.
|
||||
|
||||
Error console
|
||||
-------------
|
||||
|
@ -299,7 +295,7 @@ You might also want to set the ``style`` parameter on the Console to make error
|
|||
File output
|
||||
-----------
|
||||
|
||||
You can also tell the Console object to write to a file by setting the ``file`` argument on the constructor -- which should be a file-like object opened for writing text. You could use this to write to a file without the output ever appearing on the terminal. Here's an example::
|
||||
You can tell the Console object to write to a file by setting the ``file`` argument on the constructor -- which should be a file-like object opened for writing text. You could use this to write to a file without the output ever appearing on the terminal. Here's an example::
|
||||
|
||||
import sys
|
||||
from rich.console import Console
|
||||
|
@ -309,7 +305,7 @@ You can also tell the Console object to write to a file by setting the ``file``
|
|||
console = Console(file=report_file)
|
||||
console.rule(f"Report Generated {datetime.now().ctime()}")
|
||||
|
||||
Note that when writing to a file you may want to explicitly the ``width`` argument if you don't want to wrap the output to the current console width.
|
||||
Note that when writing to a file you may want to explicitly set the ``width`` argument if you don't want to wrap the output to the current console width.
|
||||
|
||||
Capturing output
|
||||
----------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue