diff options
author | June McEnroe <june@causal.agency> | 2020-07-10 15:26:16 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-10 15:26:16 -0400 |
commit | 1d82d8219b4018cfe02ec871a900059470666a35 (patch) | |
tree | 52ca53000fc865f55a465ffacceb9e1231e1be50 /html.c | |
parent | Implement partial table output of events (diff) | |
download | scooper-1d82d8219b4018cfe02ec871a900059470666a35.tar.gz scooper-1d82d8219b4018cfe02ec871a900059470666a35.zip |
Add IRC colors and implement nick coloring
Diffstat (limited to '')
-rw-r--r-- | html.c | 23 |
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; } |