summary refs log tree commit diff stats
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/hldiff39
-rwxr-xr-xcontrib/hldiff.py37
-rwxr-xr-xcontrib/plaintext13
-rwxr-xr-xcontrib/plaintext.py20
4 files changed, 52 insertions, 57 deletions
diff --git a/contrib/hldiff b/contrib/hldiff
new file mode 100755
index 0000000..f2bda8d
--- /dev/null
+++ b/contrib/hldiff
@@ -0,0 +1,39 @@
+#!/bin/awk -f
+BEGIN {
+	bright = "\x1B[1m"
+	red = "\x1B[31m"
+	green = "\x1B[32m"
+	cyan = "\x1B[36m"
+	reset = "\x1B[0m"
+
+	hit_diff = 0
+}
+{
+	if (hit_diff == 0) {
+		if ($0 ~ /^diff /) {
+			hit_diff = 1;
+			print bright $0 reset
+		} else if ($0 ~ /^ .*\|.*(\+|-)/) {
+			left = substr($0, 0, index($0, "|")-1)
+			right = substr($0, index($0, "|"))
+			gsub(/-+/, red "&" reset, right)
+			gsub(/\++/, green "&" reset, right)
+			print left right
+		} else {
+			print $0
+		}
+	} else {
+		if ($0 ~ /^-/) {
+			print red $0 reset
+		} else if ($0 ~ /^+/) {
+			print green $0 reset
+		} else if ($0 ~ /^ /) {
+			print $0
+		} else if ($0 ~ /^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@.*/) {
+			sub(/^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@/, cyan "&" reset)
+			print $0
+		} else {
+			print bright $0 reset
+		}
+	}
+}
diff --git a/contrib/hldiff.py b/contrib/hldiff.py
deleted file mode 100755
index f3cfd20..0000000
--- a/contrib/hldiff.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-from colorama import Fore, Style
-import sys
-import re
-
-stat_re = re.compile(r'(| \d+ )(\+*)(\-*)')
-lines_re = re.compile(r'@@ (-\d+,\d+ \+\d+,\d+) @@')
-
-sys.stdin.reconfigure(encoding='utf-8', errors='ignore')
-patch = sys.stdin.read().replace("\r\n", "\n")
-
-hit_diff = False
-for line in patch.split("\n"):
-    if line.startswith("diff "):
-        hit_diff = True
-        print(f"{Style.BRIGHT}{line}{Style.RESET_ALL}")
-        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}")
-        elif line.startswith(" "):
-            print(line)
-        else:
-            if line.startswith("@@"):
-                line = lines_re.sub(f"{Fore.CYAN}@@ \\1 @@{Style.RESET_ALL}",
-                        line)
-                print(line)
-            else:
-                print(f"{Style.BRIGHT}{line}{Style.RESET_ALL}")
-    else:
-        if line.startswith(" ") and "|" in line and ("+" in line or "-" in line):
-            line = stat_re.sub(
-                    f'\\1{Fore.GREEN}\\2{Fore.RED}\\3{Style.RESET_ALL}',
-                    line)
-        print(line)
diff --git a/contrib/plaintext b/contrib/plaintext
new file mode 100755
index 0000000..82fe57e
--- /dev/null
+++ b/contrib/plaintext
@@ -0,0 +1,13 @@
+#!/bin/awk -f
+BEGIN {
+	dim = "\x1B[2m"
+	cyan = "\x1B[36m"
+	reset = "\x1B[0m"
+}
+{
+	if ($0 ~ /On .*, .* wrote:/ || $0 ~ />+/) {
+		print dim cyan $0 reset
+	} else {
+		print $0
+	}
+}
diff --git a/contrib/plaintext.py b/contrib/plaintext.py
deleted file mode 100755
index d46991a..0000000
--- a/contrib/plaintext.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env python3
-from colorama import Fore, Style
-import sys
-import re
-
-# TODO: Wrap text to terminal width?
-
-# TODO: I guess this might vary from MUA to MUA. I've definitely seen localized
-# versions in the wild
-quote_prefix_re = re.compile(r"On .*, .* wrote:")
-quote_re = re.compile(r">+")
-
-sys.stdin.reconfigure(encoding='utf-8', errors='ignore')
-mail = sys.stdin.read().replace("\r\n", "\n")
-
-for line in mail.split("\n"):
-    if quote_re.match(line) or quote_prefix_re.match(line):
-        print(f"{Style.DIM}{Fore.CYAN}{line}{Style.RESET_ALL}")
-    else:
-        print(line)