summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-02 16:55:45 -0500
committerJune McEnroe <june@causal.agency>2020-02-02 16:55:45 -0500
commite8d0d71775e2a9602a233682e30246d7b7651e55 (patch)
tree891da0827fa533383efe3cd94dc29269e24a454a
parentAdd extremely basid handlePrivmsg (diff)
downloadcatgirl-e8d0d71775e2a9602a233682e30246d7b7651e55.tar.gz
catgirl-e8d0d71775e2a9602a233682e30246d7b7651e55.zip
Add option to show style codes
This will be used for the input window.
-rw-r--r--ui.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/ui.c b/ui.c
index 3f74e14..2445eb1 100644
--- a/ui.c
+++ b/ui.c
@@ -193,7 +193,7 @@ static short mapColor(enum Color color) {
 
 static void styleParse(struct Style *style, const char **str, size_t *len) {
 	switch (**str) {
-		break; case '\2': (*str)++; style->attr ^= A_BOLD;
+		break; case '\2':  (*str)++; style->attr ^= A_BOLD;
 		break; case '\17': (*str)++; *style = Reset;
 		break; case '\26': (*str)++; style->attr ^= A_REVERSE;
 		break; case '\35': (*str)++; style->attr ^= A_ITALIC;
@@ -230,7 +230,7 @@ static int wordWidth(const char *str) {
 	return width;
 }
 
-static void styleAdd(WINDOW *win, const char *str) {
+static void styleAdd(WINDOW *win, const char *str, bool show) {
 	int y, x, width;
 	getmaxyx(win, y, width);
 
@@ -246,7 +246,21 @@ static void styleAdd(WINDOW *win, const char *str) {
 			}
 		}
 
+		const char *code = str;
 		styleParse(&style, &str, &len);
+		if (show) {
+			wattr_set(win, A_BOLD | A_REVERSE, 0, NULL);
+			switch (*code) {
+				break; case '\2':  waddch(win, 'B');
+				break; case '\3':  waddch(win, 'C');
+				break; case '\17': waddch(win, 'O');
+				break; case '\26': waddch(win, 'R');
+				break; case '\35': waddch(win, 'I');
+				break; case '\37': waddch(win, 'U');
+			}
+			if (str - code > 1) waddnstr(win, &code[1], str - &code[1]);
+		}
+
 		size_t sp = strspn(str, " ");
 		sp += strcspn(&str[sp], " ");
 		if (sp < len) len = sp;
@@ -279,7 +293,7 @@ static void statusUpdate(void) {
 			idColors[window->id]
 		);
 		if (!window->unread) buf[unread] = '\0';
-		styleAdd(status, buf);
+		styleAdd(status, buf, true);
 	}
 	wclrtoeol(status);
 }
@@ -300,7 +314,7 @@ void uiWrite(size_t id, enum Heat heat, const struct tm *time, const char *str)
 	(void)time;
 	struct Window *window = windowFor(id);
 	waddch(window->pad, '\n');
-	styleAdd(window->pad, str);
+	styleAdd(window->pad, str, true);
 }
 
 void uiFormat(
sizeof in title setting and rewriteJason A. Donenfeld 2018-12-09git: update to v2.20.0Christian Hesse 2018-11-25ui-blame: set repo for sbJason A. Donenfeld 2018-11-25auth-filter: pass url with query string attachedJason A. Donenfeld 2018-11-21git: use xz compressed archive for downloadChristian Hesse 2018-10-12git: update to v2.19.1Christian Hesse 2018-09-11ui-ssdiff: ban strcat()Christian Hesse 2018-09-11ui-ssdiff: ban strncpy()Christian Hesse 2018-09-11ui-shared: ban strcat()Christian Hesse 2018-09-11ui-patch: ban sprintf()Christian Hesse 2018-09-11ui-log: ban strncpy()Christian Hesse 2018-09-11ui-log: ban strcpy()Christian Hesse 2018-09-11parsing: ban sprintf()Christian Hesse 2018-09-11parsing: ban strncpy()Christian Hesse 2018-08-28filters: generate anchor links from markdownChristian Hesse 2018-08-03Bump version.Jason A. Donenfeld 2018-08-03clone: fix directory traversalJason A. Donenfeld 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev