summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-31 12:57:44 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 12:57:44 -0400
commit56ea7f0e430bc44f8b652ef88bedb186b6b3e0df (patch)
treecddb410b70aafa6904fee4662beca27f4d1afebb /contrib
parent0abafa60e159f87595148c0d0fc4f5f46be2d400 (diff)
downloadaerc-56ea7f0e430bc44f8b652ef88bedb186b6b3e0df.zip
Add plaintext highlighter, escape ANSI in source
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/hldiff.py5
-rwxr-xr-xcontrib/plaintext.py21
2 files changed, 25 insertions, 1 deletions
diff --git a/contrib/hldiff.py b/contrib/hldiff.py
index 8171625..716dbce 100755
--- a/contrib/hldiff.py
+++ b/contrib/hldiff.py
@@ -3,10 +3,13 @@ from colorama import Fore, Style
import sys
import re
-patch = sys.stdin.read().replace("\r\n", "\n")
+ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
stat_re = re.compile(r'(\+*)(\-*)')
lines_re = re.compile(r'@@ (-\d+,\d+ \+\d+,\d+) @@')
+patch = sys.stdin.read().replace("\r\n", "\n")
+patch = ansi_escape.sub('', patch)
+
hit_diff = False
for line in patch.split("\n"):
if line.startswith("diff "):
diff --git a/contrib/plaintext.py b/contrib/plaintext.py
new file mode 100755
index 0000000..3502aff
--- /dev/null
+++ b/contrib/plaintext.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+from colorama import Fore, Style
+import sys
+import re
+
+# TODO: Wrap text to terminal width?
+
+ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
+# 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 [0-9: -]+( (AM|PM))?, .* wrote:")
+quote_re = re.compile(r">+ ")
+
+mail = sys.stdin.read().replace("\r\n", "\n")
+mail = ansi_escape.sub('', mail)
+
+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)