summary refs log tree commit diff
path: root/bin/hi.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-09 03:05:03 -0500
committerJune McEnroe <june@causal.agency>2019-02-09 03:05:03 -0500
commite90649c65d9007243f58abdf256ada3a188247be (patch)
tree5bbdec22004f1c16b638a15486db86595bb33b6c /bin/hi.c
parentAdd output format options to hi (diff)
downloadsrc-e90649c65d9007243f58abdf256ada3a188247be.tar.gz
src-e90649c65d9007243f58abdf256ada3a188247be.zip
Fix IRC output monospace option to emit once per line
Diffstat (limited to 'bin/hi.c')
-rw-r--r--bin/hi.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/hi.c b/bin/hi.c
index bcdb6982..347b8807 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -422,37 +422,38 @@ static const enum IRC SGRIRC[] = {
 	[SGRDefault] = 0,
 };
 
+static void ircHeader(const char *opts[]) {
+	if (opts[Monospace]) printf("%c", IRCMonospace);
+}
+
 static void
 ircOutput(const char *opts[], enum Class class, const char *str, size_t len) {
-	char mono[2] = "";
-	if (opts[Monospace]) mono[0] = IRCMonospace;
-
 	char cc[3] = "";
 	if (ANSIStyle[class][0] != SGRDefault) {
 		snprintf(cc, sizeof(cc), "%d", SGRIRC[ANSIStyle[class][0]]);
 	}
-
 	// Style each line separately, for multiple IRC messages.
 	while (len) {
 		size_t line = strcspn(str, "\n");
 		if (line > len) line = len;
 		if (ANSIStyle[class][1]) {
 			printf(
-				"%c%s%c%s%.*s%s%c",
+				"%c%s%c%.*s%c",
 				IRCColor, cc, SGRIRC[ANSIStyle[class][1]],
-				mono, (int)line, str, mono,
+				(int)line, str,
 				SGRIRC[ANSIStyle[class][2]]
 			);
 		} else {
 			// Double-toggle bold to prevent str being interpreted as color.
 			printf(
-				"%c%s%c%c%s%.*s%s",
-				IRCColor, cc, IRCBold, IRCBold, mono, (int)line, str, mono
+				"%c%s%c%c%.*s",
+				IRCColor, cc, IRCBold, IRCBold, (int)line, str
 			);
 		}
 		if (line < len) {
 			printf("\n");
 			line++;
+			if (opts[Monospace] && line < len) printf("%c", IRCMonospace);
 		}
 		str += line;
 		len -= line;
@@ -527,7 +528,7 @@ static const struct Format {
 	HeaderFn *footer;
 } Formats[] = {
 	{ "ansi", ansiOutput, NULL, NULL },
-	{ "irc",  ircOutput, NULL, NULL },
+	{ "irc",  ircOutput, ircHeader, NULL },
 	{ "html", htmlOutput, htmlHeader, htmlFooter },
 };