2020-04-02 15:59:44 +00:00
|
|
|
import io
|
2020-06-15 10:51:52 +00:00
|
|
|
import re
|
2020-04-02 15:59:44 +00:00
|
|
|
|
|
|
|
from rich.console import Console, RenderableType
|
|
|
|
|
|
|
|
|
2020-06-24 19:53:50 +00:00
|
|
|
re_link_ids = re.compile(r"id=[\d\.\-]*?;.*?\x1b")
|
2020-06-15 10:51:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def replace_link_ids(render: str) -> str:
|
2020-06-24 19:53:50 +00:00
|
|
|
"""Link IDs have a random ID and system path which is a problem for
|
|
|
|
reproducible tests.
|
|
|
|
|
|
|
|
"""
|
2020-06-15 11:05:47 +00:00
|
|
|
return re_link_ids.sub("id=0;foo\x1b", render)
|
2020-06-15 10:51:52 +00:00
|
|
|
|
|
|
|
|
2020-04-02 15:59:44 +00:00
|
|
|
def render(renderable: RenderableType) -> str:
|
2020-06-20 16:51:53 +00:00
|
|
|
console = Console(
|
|
|
|
width=100, file=io.StringIO(), color_system="truecolor", legacy_windows=False
|
|
|
|
)
|
2020-04-02 15:59:44 +00:00
|
|
|
console.print(renderable)
|
2020-06-15 10:51:52 +00:00
|
|
|
output = replace_link_ids(console.file.getvalue())
|
2020-04-02 15:59:44 +00:00
|
|
|
return output
|