diff --git a/tests/test_rich_render_text.py b/tests/test_rich_render_text.py new file mode 100644 index 0000000000..8e1e9b748d --- /dev/null +++ b/tests/test_rich_render_text.py @@ -0,0 +1,8 @@ +from typer.rich_utils import rich_render_text + + +def test_rich_render_text_returns_plain_text(): + text = "Hello 🌍" + result = rich_render_text(text) + assert "Hello" in result + assert "🌍" in result diff --git a/typer/rich_utils.py b/typer/rich_utils.py index ad110cb8d6..c55142fa0c 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -733,7 +733,8 @@ def rich_to_html(input_text: str) -> str: def rich_render_text(text: str) -> str: """Remove rich tags and render a pure text representation""" console = _get_rich_console() - return "".join(segment.text for segment in console.render(text)).rstrip("\n") + rendered = "".join(segment.text for segment in console.render(text)) + return rendered.rstrip("\n") def get_traceback(