summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-10 15:26:16 -0400
committerJune McEnroe <june@causal.agency>2020-07-10 15:26:16 -0400
commit1d82d8219b4018cfe02ec871a900059470666a35 (patch)
tree52ca53000fc865f55a465ffacceb9e1231e1be50 /html.c
parentImplement partial table output of events (diff)
downloadscooper-1d82d8219b4018cfe02ec871a900059470666a35.tar.gz
scooper-1d82d8219b4018cfe02ec871a900059470666a35.zip
Add IRC colors and implement nick coloring
Diffstat (limited to 'html.c')
-rw-r--r--html.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/html.c b/html.c
index 9f929e6..c1e4b15 100644
--- a/html.c
+++ b/html.c
@@ -237,15 +237,36 @@ static enum kcgi_err eventContext(struct khtmlreq *html, struct Event event) {
 	return error;
 }
 
+static int hash(const char *str) {
+	if (*str == '~') str++;
+	uint32_t hash = 0;
+	for (; *str; ++str) {
+		hash = (hash << 5) | (hash >> 27);
+		hash ^= *str;
+		hash *= 0x27220A95;
+	}
+	return 2 + hash % 74;
+}
+
 static enum kcgi_err eventNick(struct khtmlreq *html, struct Event event) {
+	char color[sizeof("fg99")];
+	snprintf(color, sizeof(color), "fg%02d", hash(event.user));
+
 	char *mask = NULL;
 	asprintf(&mask, "%s!%s@%s", event.nick, event.user, event.host);
 	if (!mask) err(EX_OSERR, "asprintf");
+
 	enum kcgi_err error = 0
 		|| khtml_attr(html, KELEM_TD, KATTR_CLASS, "nick", KATTR__MAX)
-		|| khtml_attr(html, KELEM_SPAN, KATTR_TITLE, mask, KATTR__MAX)
+		|| khtml_attr(
+			html, KELEM_SPAN,
+			KATTR_CLASS, color,
+			KATTR_TITLE, mask,
+			KATTR__MAX
+		)
 		|| khtml_puts(html, event.nick)
 		|| khtml_closeelem(html, 2);
+
 	free(mask);
 	return error;
 }
IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe