Skip to content

Commit 0fd6bc5

Browse files
authored
Merge pull request #2262 from Textualize/svg-default-back
fix for default background in svg export
2 parents 2c93dce + 3239e56 commit 0fd6bc5

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ 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.1] - 2022-05-08
9+
10+
### Fixed
11+
12+
- Fix for https://github.com/Textualize/rich/issues/2260
13+
14+
### Changed
15+
16+
- Added a keyline around SVG terminals which is visible on dark backgrounds
17+
818
## [12.4.0] - 2022-05-07
919

1020
### Changed
@@ -1730,7 +1740,8 @@ Major version bump for a breaking change to `Text.stylize signature`, which corr
17301740

17311741
- First official release, API still to be stabilized
17321742

1733-
[unreleased]: https://github.com/willmcgugan/rich/compare/v12.4.0...HEAD
1743+
[unreleased]: https://github.com/willmcgugan/rich/compare/v12.4.1...HEAD
1744+
[12.4.1]: https://github.com/willmcgugan/rich/compare/v12.4.0...v12.4.1
17341745
[12.4.0]: https://github.com/willmcgugan/rich/compare/v12.3.0...v12.4.0
17351746
[12.3.0]: https://github.com/willmcgugan/rich/compare/v12.2.0...v12.3.0
17361747
[12.2.0]: https://github.com/willmcgugan/rich/compare/v12.1.0...v12.2.0

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.0"
5+
version = "12.4.1"
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
CONSOLE_SVG_FORMAT = """\
2323
<svg class="rich-terminal" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
24+
<!-- Generated with Rich https://www.textualize.io -->
2425
<style>
2526
2627
@font-face {{
@@ -43,13 +44,13 @@
4344
.{unique_id}-matrix {{
4445
font-family: Fira Code, monospace;
4546
font-size: {char_height}px;
46-
font-variant: east-asian-width-values;
4747
line-height: {line_height}px;
48+
font-variant-east-asian: full-width;
4849
}}
4950
5051
.{unique_id}-title {{
5152
font-size: 18px;
52-
opacity: 0.8;
53+
5354
font-weight: bold;
5455
font-family: arial;
5556
}}

rich/console.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2252,12 +2252,12 @@ def get_svg_style(style: Style) -> str:
22522252
css_rules = []
22532253
color = (
22542254
_theme.foreground_color
2255-
if style.color is None
2255+
if (style.color is None or style.color.is_default)
22562256
else style.color.get_truecolor(_theme)
22572257
)
22582258
bgcolor = (
22592259
_theme.background_color
2260-
if style.bgcolor is None
2260+
if (style.bgcolor is None or style.bgcolor.is_default)
22612261
else style.bgcolor.get_truecolor(_theme)
22622262
)
22632263
if style.reverse:
@@ -2365,7 +2365,8 @@ def stringify(value: object) -> str:
23652365
else style.color.get_truecolor(_theme).hex
23662366
)
23672367
else:
2368-
has_background = style.bgcolor is not None
2368+
bgcolor = style.bgcolor
2369+
has_background = bgcolor is not None and not bgcolor.is_default
23692370
background = (
23702371
_theme.background_color.hex
23712372
if style.bgcolor is None
@@ -2407,12 +2408,15 @@ def stringify(value: object) -> str:
24072408
chrome = make_tag(
24082409
"rect",
24092410
fill=_theme.background_color.hex,
2411+
stroke="rgba(255,255,255,0.35)",
2412+
stroke_width="1",
24102413
x=margin_left,
24112414
y=margin_top,
24122415
width=terminal_width,
24132416
height=terminal_height,
24142417
rx=12,
24152418
)
2419+
24162420
title_color = _theme.foreground_color.hex
24172421
if title:
24182422
chrome += make_tag(

rich/terminal_theme.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,27 @@ def __init__(
127127
],
128128
)
129129

130-
131-
SVG_EXPORT_THEME = DIMMED_MONOKAI
130+
SVG_EXPORT_THEME = TerminalTheme(
131+
(41, 41, 41),
132+
(197, 200, 198),
133+
[
134+
(75, 78, 85),
135+
(204, 85, 90),
136+
(152, 168, 75),
137+
(208, 179, 68),
138+
(96, 138, 177),
139+
(152, 114, 159),
140+
(104, 160, 179),
141+
(197, 200, 198),
142+
(154, 155, 153),
143+
],
144+
[
145+
(255, 38, 39),
146+
(0, 130, 61),
147+
(208, 132, 66),
148+
(25, 132, 233),
149+
(255, 44, 122),
150+
(57, 130, 128),
151+
(253, 253, 197),
152+
],
153+
)

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 1296 118.4" xmlns="http://www.w3.org/2000/svg">\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 font-variant: east-asian-width-values;\n line-height: 26.400000000000002px;\n }\n\n .terminal-614794459-title {\n font-size: 18px;\n opacity: 0.8;\n font-weight: bold;\n font-family: arial;\n }\n\n .terminal-614794459-r1 { fill: #4f76a1;font-weight: bold }\n.terminal-614794459-r2 { fill: #b9bcba }\n </style>\n <rect fill="#191919" x="16" y="20" width="1264" height="78.4" rx="12"/><text class="terminal-614794459-title" fill="#b9bcba" text-anchor="middle" x="632" y="46">Rich</text>\n <circle cx="40" cy="40" r="7" fill="#ff5f57"/>\n <circle cx="62" cy="40" r="7" fill="#febc2e"/>\n <circle cx="84" cy="40" r="7" fill="#28c840"/>\n \n <g transform="translate(28, 60)">\n <rect fill="#be3f48" x="0" y="0" width="38.2" height="27.4"/>\n <text alignment-baseline="baseline" class="terminal-614794459-matrix" font-variant="east-asian-width-values"><tspan class="terminal-614794459-r1" x="0" y="20" textLength="37.2">foo</tspan><tspan class="terminal-614794459-r2" x="37.2" y="20" textLength="12.4">&#160;</tspan><tspan class="terminal-614794459-r2" x="49.6" y="20" textLength="62">Click</tspan><tspan class="terminal-614794459-r2" x="111.6" y="20" textLength="1128.4">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</tspan><tspan class="terminal-614794459-r2" x="1240" y="20" textLength="12.4">\n</tspan></text>\n </g>\n</svg>\n'
497+
EXPECTED_SVG = '<svg class="rich-terminal" viewBox="0 0 1296 118.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: 26.400000000000002px;\n font-variant-east-asian: full-width;\n }\n\n .terminal-614794459-title {\n font-size: 18px;\n\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="16" y="20" width="1264" height="78.4" rx="12"/><text class="terminal-614794459-title" fill="#c5c8c6" text-anchor="middle" x="632" y="46">Rich</text>\n <circle cx="40" cy="40" r="7" fill="#ff5f57"/>\n <circle cx="62" cy="40" r="7" fill="#febc2e"/>\n <circle cx="84" cy="40" r="7" fill="#28c840"/>\n \n <g transform="translate(28, 60)">\n <rect fill="#cc555a" x="0" y="0" width="38.2" height="27.4"/>\n <text alignment-baseline="baseline" class="terminal-614794459-matrix" font-variant="east-asian-width-values"><tspan class="terminal-614794459-r1" x="0" y="20" textLength="37.2">foo</tspan><tspan class="terminal-614794459-r2" x="37.2" y="20" textLength="12.4">&#160;</tspan><tspan class="terminal-614794459-r2" x="49.6" y="20" textLength="62">Click</tspan><tspan class="terminal-614794459-r2" x="111.6" y="20" textLength="1128.4">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</tspan><tspan class="terminal-614794459-r2" x="1240" y="20" textLength="12.4">\n</tspan></text>\n </g>\n</svg>\n'
498498

499499

500500
def test_export_svg():

0 commit comments

Comments
 (0)