summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-01 01:21:17 -0400
committerJune McEnroe <june@causal.agency>2019-07-01 01:21:17 -0400
commitbfd5f851951d70b8a80315cb06d281b970380d66 (patch)
tree8757d115ec21c0406fdaaa3aa772ef165549a25a
parentUse env.sh as 1sh todo list (diff)
downloadsrc-bfd5f851951d70b8a80315cb06d281b970380d66.tar.gz
src-bfd5f851951d70b8a80315cb06d281b970380d66.zip
Add diff syntax to hi
-rw-r--r--bin/hi.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/bin/hi.c b/bin/hi.c
index 463c4fcc..3f2d35cf 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -42,7 +42,9 @@ typedef unsigned Set;
 	X(Format)  \
 	X(Interp)  \
 	X(Comment) \
-	X(Todo)
+	X(Todo)    \
+	X(DiffOld) \
+	X(DiffNew)
 
 enum Class {
 #define X(class) class,
@@ -125,6 +127,14 @@ static const struct Syntax CSyntax[] = {
 };
 // }}}
 
+// diff syntax {{{
+static const struct Syntax DiffSyntax[] = {
+	{ Comment, .pattern = "^@@.*" },
+	{ DiffOld, .pattern = "^[-].*" },
+	{ DiffNew, .pattern = "^[+].*" },
+};
+// }}}
+
 // make syntax {{{
 #define MAKE_TARGET "[-./_[:alnum:]]+"
 static const struct Syntax MakeSyntax[] = {
@@ -272,6 +282,7 @@ static const struct Language {
 	size_t len;
 } Languages[] = {
 	{ "c",    "[.][chly]$", CSyntax, ARRAY_LEN(CSyntax) },
+	{ "diff", "[.](diff|patch)$", DiffSyntax, ARRAY_LEN(DiffSyntax) },
 	{ "make", "[.]mk$|^Makefile$", MakeSyntax, ARRAY_LEN(MakeSyntax) },
 	{ "mdoc", "[.][1-9]$", MdocSyntax, ARRAY_LEN(MdocSyntax) },
 	{ "rust", "[.]rs$", RustSyntax, ARRAY_LEN(RustSyntax) },
@@ -389,6 +400,8 @@ static const enum SGR ANSIStyle[ClassLen][3] = {
 	[Interp]  = { SGRYellow },
 	[Comment] = { SGRBlue },
 	[Todo]    = { SGRBlue, SGRBoldOn, SGRBoldOff },
+	[DiffOld] = { SGRRed },
+	[DiffNew] = { SGRGreen },
 };
 
 static void
@@ -495,14 +508,16 @@ static void htmlEscape(const char *str, size_t len) {
 }
 
 static const char *HTMLStyle[ClassLen] = {
-	[Keyword]  = "color: dimgray;",
-	[Macro]    = "color: green;",
-	[Tag]      = "color: inherit; text-decoration: underline;",
-	[String]   = "color: teal;",
-	[Format]   = "color: teal; font-weight: bold;",
-	[Interp]   = "color: olive;",
-	[Comment]  = "color: navy;",
-	[Todo]     = "color: navy; font-weight: bold;",
+	[Keyword] = "color: dimgray;",
+	[Macro]   = "color: green;",
+	[Tag]     = "color: inherit; text-decoration: underline;",
+	[String]  = "color: teal;",
+	[Format]  = "color: teal; font-weight: bold;",
+	[Interp]  = "color: olive;",
+	[Comment] = "color: navy;",
+	[Todo]    = "color: navy; font-weight: bold;",
+	[DiffOld] = "color: red;",
+	[DiffNew] = "color: green;",
 };
 
 static void htmlTabSize(const char *tab) {