Update hldiff.py to match git more closely
This commit is contained in:
parent
fa04a1e036
commit
411e247a80
1 changed files with 10 additions and 2 deletions
|
@ -5,20 +5,28 @@ import re
|
||||||
|
|
||||||
patch = sys.stdin.read().replace("\r\n", "\n")
|
patch = sys.stdin.read().replace("\r\n", "\n")
|
||||||
stat_re = re.compile(r'(\+*)(\-*)')
|
stat_re = re.compile(r'(\+*)(\-*)')
|
||||||
|
lines_re = re.compile(r'@@ (-\d+,\d+ \+\d+,\d+) @@')
|
||||||
|
|
||||||
hit_diff = False
|
hit_diff = False
|
||||||
for line in patch.split("\n"):
|
for line in patch.split("\n"):
|
||||||
if line.startswith("diff "):
|
if line.startswith("diff "):
|
||||||
hit_diff = True
|
hit_diff = True
|
||||||
print(line)
|
print(f"{Style.BRIGHT}{line}{Style.RESET_ALL}")
|
||||||
continue
|
continue
|
||||||
if hit_diff:
|
if hit_diff:
|
||||||
if line.startswith("-"):
|
if line.startswith("-"):
|
||||||
print(f"{Fore.RED}{line}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{line}{Style.RESET_ALL}")
|
||||||
elif line.startswith("+"):
|
elif line.startswith("+"):
|
||||||
print(f"{Fore.GREEN}{line}{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}{line}{Style.RESET_ALL}")
|
||||||
else:
|
elif line.startswith(" "):
|
||||||
print(line)
|
print(line)
|
||||||
|
else:
|
||||||
|
if line.startswith("@@"):
|
||||||
|
line = lines_re.sub(f"{Fore.BLUE}@@ \\1 @@{Style.RESET_ALL}",
|
||||||
|
line)
|
||||||
|
print(line)
|
||||||
|
else:
|
||||||
|
print(f"{Style.BRIGHT}{line}{Style.RESET_ALL}")
|
||||||
else:
|
else:
|
||||||
if line.startswith(" ") and "|" in line and ("+" in line or "-" in line):
|
if line.startswith(" ") and "|" in line and ("+" in line or "-" in line):
|
||||||
line = stat_re.sub(
|
line = stat_re.sub(
|
||||||
|
|
Loading…
Reference in a new issue