(
ranges: list[tuple[int, int]],
content: list[str],
*,
colour: str | None = None,
output: IO[str] = sys.stderr,
indent: int = 2,
)
| 73 | |
| 74 | |
| 75 | def render_diff_range( |
| 76 | ranges: list[tuple[int, int]], |
| 77 | content: list[str], |
| 78 | *, |
| 79 | colour: str | None = None, |
| 80 | output: IO[str] = sys.stderr, |
| 81 | indent: int = 2, |
| 82 | ) -> None: |
| 83 | for i, line_range in enumerate(ranges): |
| 84 | is_matching = i % 2 == 1 |
| 85 | lines = content[line_range[0] : line_range[1]] |
| 86 | for j, line in enumerate(lines): |
| 87 | if ( |
| 88 | is_matching |
| 89 | # elide the middle of matching blocks |
| 90 | and j >= 3 |
| 91 | and j < len(lines) - 3 |
| 92 | ): |
| 93 | if j == 3: |
| 94 | output.write(" " * indent + "...\n") |
| 95 | continue |
| 96 | |
| 97 | if not is_matching and colour: |
| 98 | output.write(colour) |
| 99 | |
| 100 | output.write(" " * indent + line) |
| 101 | |
| 102 | if not is_matching: |
| 103 | if colour: |
| 104 | output.write("\033[0m") |
| 105 | output.write(" (diff)") |
| 106 | |
| 107 | output.write("\n") |
| 108 | |
| 109 | |
| 110 | def dump_original_errors(errors: list[str]) -> None: |
searching dependent graphs…