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;
 }
=b23f41fcdac2904361964da6c4a909305f647fbd&follow=1'>Add AirlineJune McEnroe 2013-11-02Remove powerlineJune McEnroe 2013-11-02Rehash on reloadJune McEnroe 2013-11-02Remove git prompt from titleJune McEnroe 2013-11-02Update zsh syntax highlighting and configJune McEnroe 2013-10-31Fix host in prompt, part twoJune McEnroe 2013-10-31Fix host in promptJune McEnroe 2013-10-31Wow look reorganized zsh configJune McEnroe 2013-10-30Show hostname in prompt over SSHJune McEnroe 2013-10-30Only load chruby if it existsJune McEnroe 2013-10-27Add auto-title stuff to zshJune McEnroe 2013-10-26Add gvim alias to silence stderrJune McEnroe 2013-10-26Add home.programble.me functionJune McEnroe 2013-10-14Remove unused configsJune McEnroe 2013-10-14Add therefore, because, cards compose sequencesJune McEnroe 2013-10-14Global git ignore .swo filesJune McEnroe 2013-10-14Add Heroku to zshJune McEnroe 2013-09-23Add gst git stash aliasJune McEnroe 2013-09-06Disable some options in terminalsJune McEnroe 2013-09-05Only set colorscheme for gvimJune McEnroe 2013-09-05Remove pacman stuffJune McEnroe Goodbye Arch. 2013-09-05Only alias hub if it existsJune McEnroe 2013-09-05chruby to ruby-2.0.0June McEnroe 2013-08-17Add vim-ragtagJune McEnroe 2013-08-14Add nvmJune McEnroe 2013-07-09Add title commandJune McEnroe 2013-06-09Use default client keysJune McEnroe 2013-06-09Run games in separate X serverJune McEnroe 2013-06-08Add game wrapper to kill/restart unclutterJune McEnroe 2013-06-08Update base16-vimJune McEnroe 2013-06-08Add git configJune McEnroe