Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/enrich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading