(diff_lines: list[str])
| 231 | |
| 232 | |
| 233 | def colorize(diff_lines: list[str]) -> Generator[str, None, None]: |
| 234 | def bold(s: str) -> str: |
| 235 | return "\x1b[1m" + s + "\x1b[0m" |
| 236 | |
| 237 | def cyan(s: str) -> str: |
| 238 | return "\x1b[36m" + s + "\x1b[0m" |
| 239 | |
| 240 | def green(s: str) -> str: |
| 241 | return "\x1b[32m" + s + "\x1b[0m" |
| 242 | |
| 243 | def red(s: str) -> str: |
| 244 | return "\x1b[31m" + s + "\x1b[0m" |
| 245 | |
| 246 | for line in diff_lines: |
| 247 | if line[:4] in ["--- ", "+++ "]: |
| 248 | yield bold(line) |
| 249 | elif line.startswith("@@ "): |
| 250 | yield cyan(line) |
| 251 | elif line.startswith("+"): |
| 252 | yield green(line) |
| 253 | elif line.startswith("-"): |
| 254 | yield red(line) |
| 255 | else: |
| 256 | yield line |
| 257 | |
| 258 | |
| 259 | def print_diff(diff_lines: list[str], use_color: bool) -> None: |
no test coverage detected