summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/hi.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/bin/hi.c b/bin/hi.c
index bc560c6f..b545af75 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -312,8 +312,8 @@ typedef void OutputFn(enum Class class, const char *str, size_t len);
 // ANSI format {{{
 
 enum SGR {
-	SGRReset,
-	SGRBold,
+	SGRBoldOn = 1,
+	SGRBoldOff = 22,
 	SGRBlack = 30,
 	SGRRed,
 	SGRGreen,
@@ -322,18 +322,19 @@ enum SGR {
 	SGRMagenta,
 	SGRCyan,
 	SGRWhite,
+	SGRDefault = 39,
 };
 
-static const enum SGR ANSIStyle[ClassLen][2] = {
-	[Normal]  = { SGRReset },
+static const enum SGR ANSIStyle[ClassLen][3] = {
+	[Normal]  = { SGRDefault },
 	[Keyword] = { SGRWhite },
 	[Macro]   = { SGRGreen },
 	[String]  = { SGRCyan },
-	[Escape]  = { SGRReset },
-	[Format]  = { SGRCyan, SGRBold },
+	[Escape]  = { SGRDefault },
+	[Format]  = { SGRCyan, SGRBoldOn, SGRBoldOff },
 	[Interp]  = { SGRGreen },
 	[Comment] = { SGRBlue },
-	[Todo]    = { SGRBlue, SGRBold },
+	[Todo]    = { SGRBlue, SGRBoldOn, SGRBoldOff },
 };
 
 static void ansiOutput(enum Class class, const char *str, size_t len) {
@@ -346,7 +347,7 @@ static void ansiOutput(enum Class class, const char *str, size_t len) {
 				"\x1B[%d;%dm%.*s\x1B[%dm",
 				ANSIStyle[class][0], ANSIStyle[class][1],
 				(int)line, str,
-				SGRReset
+				ANSIStyle[class][2]
 			);
 		} else {
 			printf("\x1B[%dm%.*s", ANSIStyle[class][0], (int)line, str);
@@ -383,12 +384,11 @@ enum IRC {
 	IRCLightGray,
 	IRCBold = 0x02,
 	IRCColor = 0x03,
-	IRCReset = 0x0F,
 };
 
 static const enum IRC SGRIRC[] = {
-	[SGRReset]   = IRCReset,
-	[SGRBold]    = IRCBold,
+	[SGRBoldOn]  = IRCBold,
+	[SGRBoldOff] = IRCBold,
 	[SGRBlack]   = IRCBlack,
 	[SGRRed]     = IRCRed,
 	[SGRGreen]   = IRCGreen,
@@ -397,6 +397,7 @@ static const enum IRC SGRIRC[] = {
 	[SGRMagenta] = IRCMagenta,
 	[SGRCyan]    = IRCCyan,
 	[SGRWhite]   = IRCGray,
+	[SGRDefault] = 0,
 };
 
 static void ircOutput(enum Class class, const char *str, size_t len) {
@@ -404,23 +405,23 @@ static void ircOutput(enum Class class, const char *str, size_t len) {
 	while (len) {
 		size_t line = strcspn(str, "\n");
 		if (line > len) line = len;
+		char cc[3] = "";
+		if (ANSIStyle[class][0] != SGRDefault) {
+			snprintf(cc, sizeof(cc), "%d", SGRIRC[ANSIStyle[class][0]]);
+		}
 		if (ANSIStyle[class][1]) {
 			printf(
-				"%c%d%c%.*s%c",
-				IRCColor, SGRIRC[ANSIStyle[class][0]],
-				SGRIRC[ANSIStyle[class][1]],
+				"%c%s%c%.*s%c",
+				IRCColor, cc, SGRIRC[ANSIStyle[class][1]],
 				(int)line, str,
-				IRCReset
+				SGRIRC[ANSIStyle[class][2]]
 			);
-		} else if (ANSIStyle[class][0]) {
+		} else {
 			// Double-toggle bold to prevent str being interpreted as color.
 			printf(
-				"%c%d%c%c%.*s",
-				IRCColor, SGRIRC[ANSIStyle[class][0]], IRCBold, IRCBold,
-				(int)line, str
+				"%c%s%c%c%.*s",
+				IRCColor, cc, IRCBold, IRCBold, (int)line, str
 			);
-		} else {
-			printf("%c%.*s", IRCReset, (int)line, str);
 		}
 		if (line < len) {
 			printf("\n");
June McEnroe 2021-01-12Don't output a pre in hilex by defaultJune McEnroe 2021-01-12Move hilex out of hilex directoryJune McEnroe 2021-01-12Consolidate hilex formatters into hilex.cJune McEnroe 2021-01-12Remove hacky tagging from hilexJune McEnroe God that makes the lexers so much simpler. 2021-01-12Add htagml -iJune McEnroe 2021-01-12Render tag index in HTMLJune McEnroe 2021-01-12Add htagml -xJune McEnroe 2021-01-12Prevent matching the same tag twiceJune McEnroe 2021-01-12Process htagml file line by lineJune McEnroe This simplifies some things, adds support for line number tag definitions, and should enable combining htagml with other preprocessors in the future. 2021-01-12Split fields by tab onlyJune McEnroe Also don't fail hard on non-forward-search definitions. 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe neovim is laggy as hell in my OpenBSD VM, so I switched to vi so I could type without getting frustrated. 2021-01-09Add c -t flag to print expression typeJune McEnroe Also add missing float case. 2021-01-05Update taglineJune McEnroe