From 8403a5627b7e41dc621b854b54ac45c475923737 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 7 Jul 2020 16:49:30 +0100 Subject: [PATCH] windows fix --- rich/_windows.py | 5 ++++- rich/highlighter.py | 2 +- tests/test_log.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rich/_windows.py b/rich/_windows.py index bb051e97..656644a0 100644 --- a/rich/_windows.py +++ b/rich/_windows.py @@ -17,7 +17,7 @@ try: from ctypes import LibraryLoader windll = LibraryLoader(ctypes.WinDLL) # type: ignore -except (AttributeError, ImportError): +except (AttributeError, ImportError, ValueError): # Fallback if we can't load the Windows DLL def get_windows_console_features() -> WindowsConsoleFeatures: @@ -60,8 +60,11 @@ else: if __name__ == "__main__": + import platform + features = get_windows_console_features() from rich import print + print(f'platform="{platform.system()}"') print(repr(features)) diff --git a/rich/highlighter.py b/rich/highlighter.py index 758ddad0..b4c1adc0 100644 --- a/rich/highlighter.py +++ b/rich/highlighter.py @@ -73,7 +73,7 @@ class ReprHighlighter(RegexHighlighter): highlights = [ r"(?P[\{\[\(\)\]\}])", r"(?P\<)(?P\w*)(?P.*?)(?P\>)", - r"(?P\w+?)=(?P\"?\S+?\"?)", + r"(?P\w+?)=(?P\"?[\w_]+\"?)", r"(?PTrue)|(?PFalse)|(?PNone)", r"(?P(?0x[0-9a-f]*)", diff --git a/tests/test_log.py b/tests/test_log.py index 28098ae7..edafaa02 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -27,7 +27,7 @@ def render_log(): def test_log(): - expected = "\n\x1b[2;36m[TIME]\x1b[0m\x1b[2;36m \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m8\x1b[0m\x1b[1;34m0\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m ! \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:24\x1b[0m\n\x1b[2;36m \x1b[0m\x1b[2;36m \x1b[0m\x1b[1m[\x1b[0m\x1b[1;34m1\x1b[0m, \x1b[1;34m2\x1b[0m, \x1b[1;34m3\x1b[0m\x1b[1m]\x1b[0m \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:25\x1b[0m\n \x1b[3m Locals \x1b[0m \n \x1b[34m╭─────────┬────────────────────────────────────────╮\x1b[0m \n \x1b[34m│\x1b[0m\x1b[32m'console'\x1b[0m\x1b[34m│\x1b[0m\x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m8\x1b[0m\x1b[1;34m0\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m\x1b[34m│\x1b[0m \n \x1b[34m╰─────────┴────────────────────────────────────────╯\x1b[0m \n" + expected = "\n\x1b[2;36m[TIME]\x1b[0m\x1b[2;36m \x1b[0mHello from \x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m ! \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:24\x1b[0m\n\x1b[2;36m \x1b[0m\x1b[2;36m \x1b[0m\x1b[1m[\x1b[0m\x1b[1;34m1\x1b[0m, \x1b[1;34m2\x1b[0m, \x1b[1;34m3\x1b[0m\x1b[1m]\x1b[0m \x1b]8;id=0;foo\x1b\\\x1b[2mtest_log.py\x1b[0m\x1b]8;;\x1b\\\x1b[2m:25\x1b[0m\n \x1b[3m Locals \x1b[0m \n \x1b[34m╭─────────┬────────────────────────────────────────╮\x1b[0m \n \x1b[34m│\x1b[0m\x1b[32m'console'\x1b[0m\x1b[34m│\x1b[0m\x1b[1m<\x1b[0m\x1b[1;38;5;13mconsole\x1b[0m\x1b[39m \x1b[0m\x1b[3;33mwidth\x1b[0m\x1b[39m=\x1b[0m\x1b[1;34m80\x1b[0m\x1b[39m ColorSystem.TRUECOLOR\x1b[0m\x1b[1m>\x1b[0m\x1b[34m│\x1b[0m \n \x1b[34m╰─────────┴────────────────────────────────────────╯\x1b[0m \n" assert render_log() == expected