1
0
Fork 0
mirror of https://github.com/Findus23/apt-summary.git synced 2024-09-18 14:33:45 +02:00

color difference in versions

Inspired by nala
This commit is contained in:
Lukas Winkler 2024-04-25 23:34:43 +02:00
parent babb902b9e
commit b2875630ff
Signed by: lukas
GPG key ID: 54DE4D798D244853
3 changed files with 32 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.idea/
__pycache__/

27
diff.py Normal file
View file

@ -0,0 +1,27 @@
from difflib import SequenceMatcher
COLOR_BLUE = '\033[34m'
ENDC = '\033[0m'
def get_diff(a: str, b: str) -> str:
sm = SequenceMatcher(None, a, b)
output = []
for opcode, a0, a1, b0, b1 in sm.get_opcodes():
if opcode == 'equal':
output.append(a[a0:a1])
elif opcode in ['insert', 'replace']:
output.append(COLOR_BLUE + b[b0:b1] + ENDC)
elif opcode == 'delete':
...
# output.append("<del>" + seqm.a[a0:a1] + "</del>")
else:
raise RuntimeError("unexpected opcode")
return ''.join(output)
if __name__ == '__main__':
a = "Wort"
b = "Woort"
print(get_diff(a, b))

View file

@ -8,6 +8,8 @@ from typing import Union
from packaging import version
from packaging.version import Version, InvalidVersion
from diff import get_diff
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
SomeVersion = Union[Version]
@ -86,12 +88,13 @@ for update in UpdateType:
text += update.value.center(width, "-")
for update in sub_updates:
diff_text = get_diff(update.old_version, update.new_version)
text += (
f"{update.name:<{max(len(u.name) for u in sub_updates)}}"
" "
f"{update.old_version:<{max(len(u.old_version) for u in sub_updates)}}"
""
f"{update.new_version:<{max(len(u.old_version) for u in sub_updates)}}"
f"{diff_text:<{max(len(u.old_version) for u in sub_updates)}}"
"\n"
)