aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-06-07 11:53:42 -0400
committerDrew DeVault <sir@cmpwn.com>2019-06-07 11:54:01 -0400
commit6e61f58d8684ae8879482d371219d8ae5c00a39d (patch)
tree0df30b81471485779433e86457062a5cf2fcd0d2 /contrib
parent0647ea64839df5ceecf3a71f672f05a589fd1409 (diff)
downloadaerc-6e61f58d8684ae8879482d371219d8ae5c00a39d.tar.gz
Rewrite Python filters in awk
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 00000000..f2bda8d5
--- /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 f3cfd202..00000000
--- 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 00000000..82fe57ee
--- /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 d46991a7..00000000
--- 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)