From fa04a1e036a418258451466d99de34a9546a9965 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 30 Mar 2019 14:12:04 -0400 Subject: Add basic message viewer mockup --- contrib/hldiff.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 contrib/hldiff.py (limited to 'contrib') diff --git a/contrib/hldiff.py b/contrib/hldiff.py new file mode 100755 index 0000000..e12f688 --- /dev/null +++ b/contrib/hldiff.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +from colorama import Fore, Style +import sys +import re + +patch = sys.stdin.read().replace("\r\n", "\n") +stat_re = re.compile(r'(\+*)(\-*)') + +hit_diff = False +for line in patch.split("\n"): + if line.startswith("diff "): + hit_diff = True + print(line) + continue + if hit_diff: + if line.startswith("-"): + print(f"{Fore.RED}{line}{Style.RESET_ALL}") + elif line.startswith("+"): + print(f"{Fore.GREEN}{line}{Style.RESET_ALL}") + else: + print(line) + else: + if line.startswith(" ") and "|" in line and ("+" in line or "-" in line): + line = stat_re.sub( + f'{Fore.GREEN}\\1{Fore.RED}\\2{Style.RESET_ALL}', + line) + print(line) -- cgit 1.4.1-2-gfad0