| 1 |
import io |
| 2 |
import re |
| 3 |
|
| 4 |
from rich.console import Console, RenderableType |
| 5 |
|
| 6 |
|
| 7 |
re_link_ids = re.compile(r"id=[\d.\-]*?;.*?\x1b") |
| 8 |
|
| 9 |
|
| 10 |
def replace_link_ids(render: str) -> str: |
| 11 |
"""Link IDs have a random ID and system path which is a problem for |
| 12 |
reproducible tests. |
| 13 |
|
| 14 |
""" |
| 15 |
return re_link_ids.sub("id=0;foo\x1b", render) |
| 16 |
|
| 17 |
|
| 18 |
def render(renderable: RenderableType, no_wrap: bool = False) -> str: |
| 19 |
console = Console( |
| 20 |
width=100, file=io.StringIO(), color_system="truecolor", legacy_windows=False |
| 21 |
) |
| 22 |
console.print(renderable, no_wrap=no_wrap) |
| 23 |
output = replace_link_ids(console.file.getvalue()) |
| 24 |
return output |