summary refs log tree commit diff
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
commitdd3cbc82d04c2b89a28c0affec8f45a2557f021a (patch)
tree4a01f3cd195d3c08268d03e13a89074f733c2e28
parentAdd output format options to hi (diff)
downloadsrc-dd3cbc82d04c2b89a28c0affec8f45a2557f021a.tar.gz
src-dd3cbc82d04c2b89a28c0affec8f45a2557f021a.zip
Fix IRC output monospace option to emit once per line
-rw-r--r--bin/hi.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/hi.c b/bin/hi.c
index 3087fb92..902bd391 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 },
 };