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
commite90649c65d9007243f58abdf256ada3a188247be (patch)
tree5bbdec22004f1c16b638a15486db86595bb33b6c
parentAdd output format options to hi (diff)
downloadsrc-e90649c65d9007243f58abdf256ada3a188247be.tar.gz
src-e90649c65d9007243f58abdf256ada3a188247be.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 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 },
 };
 
class='logheader'>2020-02-20Remove wiki scriptJune McEnroe Wikipedia seems to have removed the one-sentence extracts from the opensearch results. Too bad. It's not a wiki script, what we need is a command that fetches single-sentence summaries of articles on Wikipedia. 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe One from the cafe that caught my attention. 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe Apparently sometimes it didn't like receiving its own internal storage to parse again. Understandable. 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe Wow. One of the best I've read. 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe Broke out LDLIBS for each bin, and made everything more uniform. 2020-01-28Change scout sensitivity to 1.4June McEnroe idk it seems to work. 2020-01-28Import shows.txtJune McEnroe