From 95049662d6bcc50fcee95ea3a25860161641adf2 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 2 May 2022 20:18:28 +0100 Subject: [PATCH] fix background --- rich/console.py | 6 ++++-- tests/test_console.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rich/console.py b/rich/console.py index c1947ce7..dc59fe38 100644 --- a/rich/console.py +++ b/rich/console.py @@ -2302,7 +2302,7 @@ class Console: def escape_text(text: str) -> str: """HTML escape text and replace spaces with nbsp.""" - return escape(text).replace(" ", "\u00A0") + return escape(text).replace(" ", " ") def make_tag( name: str, content: Optional[str] = None, **attribs: object @@ -2346,12 +2346,14 @@ class Console: class_name = f"r{classes[rules]}" if style.reverse: + has_background = True background = ( _theme.foreground_color.hex if style.color is None else style.color.get_truecolor(_theme).hex ) else: + has_background = style.bgcolor is not None background = ( _theme.background_color.hex if style.bgcolor is None @@ -2359,7 +2361,7 @@ class Console: ) text_length = cell_len(text) - if background is not None: + if has_background: text_backgrounds.append( make_tag( "rect", diff --git a/tests/test_console.py b/tests/test_console.py index fc3b19a6..cdddf09a 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -493,7 +493,7 @@ def test_export_html_inline(): assert html == expected -EXPECTED_SVG = '\n \n Rich\n \n \n \n \n \n \n foo\xa0Click\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\n\n \n\n' +EXPECTED_SVG = '\n \n Rich\n \n \n \n \n \n \n foo Click                                                                                           \n\n \n\n' def test_export_svg(): @@ -515,7 +515,7 @@ def test_save_svg(): with tempfile.TemporaryDirectory() as path: export_path = os.path.join(path, "example.svg") console.save_svg(export_path) - with open(export_path, "rt") as svg_file: + with open(export_path, "rt", encoding="utf-8") as svg_file: assert svg_file.read() == EXPECTED_SVG