about summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
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;
 }