Skip to content

Commit

Permalink
Merge branch 'master' into fix_default_ensure_ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Sep 23, 2022
2 parents c49e5a7 + 28a05fa commit 4e704fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for `FORCE_COLOR` env var https://github.com/Textualize/rich/pull/2449

This comment has been minimized.

Copy link
@Aedd9m
- Allow a `max_depth` argument to be passed to the `install()` hook https://github.com/Textualize/rich/issues/2486
- Document using `None` as name in `__rich_repr__` for tuple positional args https://github.com/Textualize/rich/pull/2379
- Add `font_aspect_ratio` parameter in SVG export https://github.com/Textualize/rich/pull/2539/files

### Fixed

Expand All @@ -22,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix pretty printer handling of cyclic references https://github.com/Textualize/rich/pull/2524
- Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495
- Fix mismatching default value of parameter `ensure_ascii` https://github.com/Textualize/rich/pull/2538
- Remove unused height parameter in `Layout` class https://github.com/Textualize/rich/pull/2540


### Changed

Expand Down
19 changes: 14 additions & 5 deletions rich/console.py
Expand Up @@ -2261,18 +2261,22 @@ def export_svg(
theme: Optional[TerminalTheme] = None,
clear: bool = True,
code_format: str = CONSOLE_SVG_FORMAT,
font_aspect_ratio: float = 0.61,
) -> str:
"""
Generate an SVG from the console contents (requires record=True in Console constructor).
Args:
path (str): The path to write the SVG to.
title (str): The title of the tab in the output image
title (str, optional): The title of the tab in the output image
theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
code_format (str): Format string used to generate the SVG. Rich will inject a number of variables
code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables
into the string in order to form the final SVG output. The default template used and the variables
injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
If you aren't specifying a different font inside ``code_format``, you probably don't need this.
"""

from rich.cells import cell_len
Expand Down Expand Up @@ -2316,7 +2320,7 @@ def get_svg_style(style: Style) -> str:

width = self.width
char_height = 20
char_width = char_height * 0.61
char_width = char_height * font_aspect_ratio
line_height = char_height * 1.22

margin_top = 1
Expand Down Expand Up @@ -2505,23 +2509,28 @@ def save_svg(
theme: Optional[TerminalTheme] = None,
clear: bool = True,
code_format: str = CONSOLE_SVG_FORMAT,
font_aspect_ratio: float = 0.61,
) -> None:
"""Generate an SVG file from the console contents (requires record=True in Console constructor).
Args:
path (str): The path to write the SVG to.
title (str): The title of the tab in the output image
title (str, optional): The title of the tab in the output image
theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
code_format (str): Format string used to generate the SVG. Rich will inject a number of variables
code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables
into the string in order to form the final SVG output. The default template used and the variables
injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
If you aren't specifying a different font inside ``code_format``, you probably don't need this.
"""
svg = self.export_svg(
title=title,
theme=theme,
clear=clear,
code_format=code_format,
font_aspect_ratio=font_aspect_ratio,
)
with open(path, "wt", encoding="utf-8") as write_file:
write_file.write(svg)
Expand Down
4 changes: 1 addition & 3 deletions rich/layout.py
Expand Up @@ -20,8 +20,8 @@
from .highlighter import ReprHighlighter
from .panel import Panel
from .pretty import Pretty
from .repr import rich_repr, Result
from .region import Region
from .repr import Result, rich_repr
from .segment import Segment
from .style import StyleType

Expand Down Expand Up @@ -162,15 +162,13 @@ def __init__(
minimum_size: int = 1,
ratio: int = 1,
visible: bool = True,
height: Optional[int] = None,
) -> None:
self._renderable = renderable or _Placeholder(self)
self.size = size
self.minimum_size = minimum_size
self.ratio = ratio
self.name = name
self.visible = visible
self.height = height
self.splitter: Splitter = self.splitters["column"]()
self._children: List[Layout] = []
self._render_map: RenderMap = {}
Expand Down

0 comments on commit 4e704fa

Please sign in to comment.