| 1 |
import json |
| 2 |
import io |
| 3 |
from time import time |
| 4 |
from rich.console import Console |
| 5 |
from rich.pretty import Pretty |
| 6 |
|
| 7 |
|
| 8 |
console = Console(file=io.StringIO(), color_system="truecolor", width=100) |
| 9 |
|
| 10 |
with open("cats.json") as fh: |
| 11 |
cats = json.load(fh) |
| 12 |
|
| 13 |
|
| 14 |
console.begin_capture() |
| 15 |
start = time() |
| 16 |
pretty = Pretty(cats) |
| 17 |
console.print(pretty, overflow="ignore", crop=False) |
| 18 |
result = console.end_capture() |
| 19 |
taken = (time() - start) * 1000 |
| 20 |
print(result) |
| 21 |
|
| 22 |
print(console.file.getvalue()) |
| 23 |
print(f"{taken:.1f}") |