Skip to content

Commit 9bfb619

Browse files
authored
Merge pull request #2289 from Textualize/svg-tweak
Svg tweak
2 parents 58bfa48 + 2d44195 commit 9bfb619

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [12.4.3] - 2022-05-23
9+
10+
### Changed
11+
12+
- Further tweaks to SVG character matrix
13+
- Added clip rect to SVG to prevent box characters overlapping bottom of terminal
14+
815
## [12.4.2] - 2022-05-23
916

1017
### Fixed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "12.4.2"
5+
version = "12.4.3"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <[email protected]>"]
88
license = "MIT"

rich/_export_format.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@
5656
5757
{styles}
5858
</style>
59+
60+
<defs>
61+
<clipPath id="{unique_id}-clip-terminal">
62+
<rect x="0" y="0" width="{terminal_width}" height="{terminal_height}" />
63+
</clipPath>
64+
</defs>
65+
5966
{chrome}
60-
<g transform="translate({terminal_x}, {terminal_y})">
67+
<g transform="translate({terminal_x}, {terminal_y})" clip-path="url(#{unique_id}-clip-terminal)">
6168
{backgrounds}
6269
<g class="{unique_id}-matrix">
6370
{matrix}

rich/console.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ def get_svg_style(style: Style) -> str:
22922292

22932293
padding_top = 40
22942294
padding_right = 8
2295-
padding_bottom = 12
2295+
padding_bottom = 8
22962296
padding_left = 8
22972297

22982298
padding_width = padding_left + padding_right
@@ -2380,9 +2380,9 @@ def stringify(value: object) -> str:
23802380
"rect",
23812381
fill=background,
23822382
x=x * char_width,
2383-
y=y * line_height,
2384-
width=char_width * text_length + 1,
2385-
height=line_height + 1,
2383+
y=y * line_height + 1.5,
2384+
width=char_width * text_length,
2385+
height=line_height + 0.25,
23862386
)
23872387
)
23882388

@@ -2416,7 +2416,7 @@ def stringify(value: object) -> str:
24162416
y=margin_top,
24172417
width=terminal_width,
24182418
height=terminal_height,
2419-
rx=12,
2419+
rx=8,
24202420
)
24212421

24222422
title_color = _theme.foreground_color.hex
@@ -2431,7 +2431,7 @@ def stringify(value: object) -> str:
24312431
y=margin_top + char_height + 6,
24322432
)
24332433
chrome += f"""
2434-
<g transform="translate(30,24)">
2434+
<g transform="translate(26,22)">
24352435
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
24362436
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
24372437
<circle cx="44" cy="0" r="7" fill="#28c840"/>
@@ -2443,6 +2443,8 @@ def stringify(value: object) -> str:
24432443
char_width=char_width,
24442444
char_height=char_height,
24452445
line_height=line_height,
2446+
terminal_width=char_width * width,
2447+
terminal_height=(y + 1) * line_height,
24462448
width=terminal_width + margin_width,
24472449
height=terminal_height + margin_height,
24482450
terminal_x=margin_left + padding_left,

tests/test_console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_export_html_inline():
494494
assert html == expected
495495

496496

497-
EXPECTED_SVG = '<svg class="rich-terminal" viewBox="0 0 1238 78.4" xmlns="http://www.w3.org/2000/svg">\n <!-- Generated with Rich https://www.textualize.io -->\n <style>\n\n @font-face {\n font-family: "Fira Code";\n src: local("FiraCode-Regular"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");\n font-style: normal;\n font-weight: 400;\n }\n @font-face {\n font-family: "Fira Code";\n src: local("FiraCode-Bold"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");\n font-style: bold;\n font-weight: 700;\n }\n\n .terminal-614794459-matrix {\n font-family: Fira Code, monospace;\n font-size: 20px;\n line-height: 24.4px;\n font-variant-east-asian: full-width;\n }\n\n .terminal-614794459-title {\n font-size: 18px;\n font-weight: bold;\n font-family: arial;\n }\n\n .terminal-614794459-r1 { fill: #608ab1;font-weight: bold }\n.terminal-614794459-r2 { fill: #c5c8c6 }\n </style>\n <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1236" height="76.4" rx="12"/><text class="terminal-614794459-title" fill="#c5c8c6" text-anchor="middle" x="618" y="27">Rich</text>\n <g transform="translate(30,24)">\n <circle cx="0" cy="0" r="7" fill="#ff5f57"/>\n <circle cx="22" cy="0" r="7" fill="#febc2e"/>\n <circle cx="44" cy="0" r="7" fill="#28c840"/>\n </g>\n \n <g transform="translate(9, 41)">\n <rect fill="#cc555a" x="0" y="0" width="37.6" height="25.4"/>\n <g class="terminal-614794459-matrix">\n <text class="terminal-614794459-r1" x="0" y="20" textLength="36.6">foo</text><text class="terminal-614794459-r2" x="48.8" y="20" textLength="61">Click</text><text class="terminal-614794459-r2" x="1220" y="20" textLength="12.2">\n</text>\n </g>\n </g>\n</svg>\n'
497+
EXPECTED_SVG = '<svg class="rich-terminal" viewBox="0 0 1238 74.4" xmlns="http://www.w3.org/2000/svg">\n <!-- Generated with Rich https://www.textualize.io -->\n <style>\n\n @font-face {\n font-family: "Fira Code";\n src: local("FiraCode-Regular"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");\n font-style: normal;\n font-weight: 400;\n }\n @font-face {\n font-family: "Fira Code";\n src: local("FiraCode-Bold"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),\n url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");\n font-style: bold;\n font-weight: 700;\n }\n\n .terminal-614794459-matrix {\n font-family: Fira Code, monospace;\n font-size: 20px;\n line-height: 24.4px;\n font-variant-east-asian: full-width;\n }\n\n .terminal-614794459-title {\n font-size: 18px;\n font-weight: bold;\n font-family: arial;\n }\n\n .terminal-614794459-r1 { fill: #608ab1;font-weight: bold }\n.terminal-614794459-r2 { fill: #c5c8c6 }\n </style>\n\n <defs>\n <clipPath id="terminal-614794459-clip-terminal">\n <rect x="0" y="0" width="1220.0" height="24.4" />\n </clipPath>\n </defs>\n\n <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1236" height="72.4" rx="8"/><text class="terminal-614794459-title" fill="#c5c8c6" text-anchor="middle" x="618" y="27">Rich</text>\n <g transform="translate(26,22)">\n <circle cx="0" cy="0" r="7" fill="#ff5f57"/>\n <circle cx="22" cy="0" r="7" fill="#febc2e"/>\n <circle cx="44" cy="0" r="7" fill="#28c840"/>\n </g>\n \n <g transform="translate(9, 41)" clip-path="url(#terminal-614794459-clip-terminal)">\n <rect fill="#cc555a" x="0" y="1.5" width="36.6" height="24.65"/>\n <g class="terminal-614794459-matrix">\n <text class="terminal-614794459-r1" x="0" y="20" textLength="36.6">foo</text><text class="terminal-614794459-r2" x="48.8" y="20" textLength="61">Click</text><text class="terminal-614794459-r2" x="1220" y="20" textLength="12.2">\n</text>\n </g>\n </g>\n</svg>\n'
498498

499499

500500
def test_export_svg():

0 commit comments

Comments
 (0)