diff --git a/src/enrich/console.py b/src/enrich/console.py index a56dd00..8e2f56c 100644 --- a/src/enrich/console.py +++ b/src/enrich/console.py @@ -6,6 +6,7 @@ import rich.console as rich_console from rich.ansi import AnsiDecoder +from rich.containers import Lines from rich.file_proxy import FileProxy @@ -48,8 +49,10 @@ def print(self, *args, **kwargs) -> None: # type: ignore if args and isinstance(args[0], str) and "\033" in args[0]: text = format(*args) + "\n" decoder = AnsiDecoder() - args = list(decoder.decode(text)) # type: ignore - super().print(*args, **kwargs) + args = Lines(decoder.decode(text)) # type: ignore[assignment] + super().print(args, **kwargs) + else: + super().print(*args, **kwargs) # Based on Ansible implementation diff --git a/test/test_console.py b/test/test_console.py index 43d8ad3..d619e5b 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -56,10 +56,10 @@ def test_console_soft_wrap() -> None: def test_console_print_ansi() -> None: """Validates that Console.print() with ANSI does not make break them.""" console = Console(force_terminal=True, record=True, soft_wrap=True, redirect=True) - text = "\033[92mfuture is green!\033[0m" + text = "\033[92mfuture is green!\033[0m\nwowsers!" console.print(text) text_result = console.export_text(clear=False) - assert "future is green!" in text_result + assert "future is green!\nwowsers!" in text_result html_result = console.export_html() assert "#00ff00" in html_result