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
commit97d904239c08c55acc815ba127478bfed2429d3b (patch)
tree837a17f3acf9094ddb957fa9cae65c16ed019b16
parentUse env.sh as 1sh todo list (diff)
downloadsrc-97d904239c08c55acc815ba127478bfed2429d3b.tar.gz
src-97d904239c08c55acc815ba127478bfed2429d3b.zip
Add diff syntax to hi
Diffstat (limited to '')
-rw-r--r--bin/hi.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/bin/hi.c b/bin/hi.c
index 866fc651..9bc6aaa2 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) {