MCPcopy
hub / github.com/psf/black / color_diff

Function color_diff

src/black/output.py:96–109  ·  view source on GitHub ↗

Inject the ANSI color codes to the diff.

(contents: str)

Source from the content-addressed store, hash-verified

94
95
96def color_diff(contents: str) -> str:
97 """Inject the ANSI color codes to the diff."""
98 lines = contents.split("\n")
99 for i, line in enumerate(lines):
100 if line.startswith("+++") or line.startswith("---"):
101 line = "\033[1m" + line + "\033[0m" # bold, reset
102 elif line.startswith("@@"):
103 line = "\033[36m" + line + "\033[0m" # cyan, reset
104 elif line.startswith("+"):
105 line = "\033[32m" + line + "\033[0m" # green, reset
106 elif line.startswith("-"):
107 line = "\033[31m" + line + "\033[0m" # red, reset
108 lines[i] = line
109 return "\n".join(lines)
110
111
112@mypyc_attr(patchable=True)

Callers 3

format_file_in_placeFunction · 0.90
format_stdin_to_stdoutFunction · 0.90

Calls

no outgoing calls

Tested by 1