MCPcopy
hub / github.com/Textualize/rich / save_svg

Method save_svg

rich/console.py:2606–2642  ·  view source on GitHub ↗

Generate an SVG file from the console contents (requires record=True in Console constructor). Args: path (Union[str, PathLike[str]]): The path to write the SVG to. title (str, optional): The title of the tab in the output image theme (TerminalTheme, optio

(
        self,
        path: Union[str, PathLike[str]],
        *,
        title: str = "Rich",
        theme: Optional[TerminalTheme] = None,
        clear: bool = True,
        code_format: str = CONSOLE_SVG_FORMAT,
        font_aspect_ratio: float = 0.61,
        unique_id: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

2604 return svg
2605
2606 def save_svg(
2607 self,
2608 path: Union[str, PathLike[str]],
2609 *,
2610 title: str = "Rich",
2611 theme: Optional[TerminalTheme] = None,
2612 clear: bool = True,
2613 code_format: str = CONSOLE_SVG_FORMAT,
2614 font_aspect_ratio: float = 0.61,
2615 unique_id: Optional[str] = None,
2616 ) -> None:
2617 """Generate an SVG file from the console contents (requires record=True in Console constructor).
2618
2619 Args:
2620 path (Union[str, PathLike[str]]): The path to write the SVG to.
2621 title (str, optional): The title of the tab in the output image
2622 theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
2623 clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
2624 code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables
2625 into the string in order to form the final SVG output. The default template used and the variables
2626 injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
2627 font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
2628 string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
2629 If you aren't specifying a different font inside ``code_format``, you probably don't need this.
2630 unique_id (str, optional): unique id that is used as the prefix for various elements (CSS styles, node
2631 ids). If not set, this defaults to a computed value based on the recorded content.
2632 """
2633 svg = self.export_svg(
2634 title=title,
2635 theme=theme,
2636 clear=clear,
2637 code_format=code_format,
2638 font_aspect_ratio=font_aspect_ratio,
2639 unique_id=unique_id,
2640 )
2641 with open(path, "w", encoding="utf-8") as write_file:
2642 write_file.write(svg)
2643
2644
2645if __name__ == "__main__": # pragma: no cover

Callers 2

test_save_svgFunction · 0.95
save_table_svg.pyFile · 0.80

Calls 3

export_svgMethod · 0.95
openFunction · 0.85
writeMethod · 0.45

Tested by 1

test_save_svgFunction · 0.76