cio

a simple irc client
git clone git://kloet.net/cio
Download | Log | Files | Refs | README | LICENSE

commit c0a33e526ccb86801fb9c825499f8f1e97880f07
parent dcff8b64e7e03fb1a73fd4f215299851860f6912
Author: Andrew Kloet <andrew@kloet.net>
Date:   Wed, 17 Jun 2026 15:09:54 -0400

update colornames patch

Diffstat:
Mpatches/colornames.diff | 72++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/patches/colornames.diff b/patches/colornames.diff @@ -1,8 +1,8 @@ - cio.c | 34 ++++++++++++++++++++++++++++++++-- - 1 file changed, 32 insertions(+), 2 deletions(-) + cio.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/cio.c b/cio.c -index d1a70aa..7d0f00b 100644 +index d0577a8..502506e 100644 --- a/cio.c +++ b/cio.c @@ -51,8 +51,8 @@ @@ -16,7 +16,7 @@ index d1a70aa..7d0f00b 100644 #define SRV "irc.oftc.net" #define PORT "6697" -@@ -153,6 +153,14 @@ empty(const char *str) { +@@ -164,6 +164,14 @@ empty(const char *str) { return (str == NULL || str[0] == '\0'); } @@ -24,44 +24,25 @@ index d1a70aa..7d0f00b 100644 +nickhash(const char *s) +{ + unsigned int h = 5381; -+ while (*s) h = ((h << 5) + h) + (*s++); ++ while (*s != '\x03') h = ((h << 5) + h) + (*s++); + return (h % 6) + 2; /* Use pairs 2-7 */ +} + static void sndf(const char *fmt, ...) { -@@ -340,6 +348,7 @@ pushl(char *p, char *e) - wchar_t wc; - int n, cl; - cchar_t cc; -+ int color = 0; - char *eol = memchr(p, '\n', e - p); - - if (!eol) eol = e; -@@ -349,6 +358,21 @@ pushl(char *p, char *e) - mbtowc(NULL, NULL, 0); - wc = L'?'; n = 1; - } +@@ -375,6 +383,10 @@ pushl(struct Chan *c, char *p, char *e) + mbtowc(NULL, NULL, 0); + while (p < eol) { + int n = mbtowc(&wc, p, eol - p); + if (wc == L'\x03') { + p += n; -+ if (color) { -+ wattroff(scr.mw, COLOR_PAIR(color)); -+ color = 0; -+ continue; -+ } -+ char nb[64]; -+ char *found = memccpy(nb, p, '\x03', sizeof(nb) - 1); -+ if (found) { -+ *(found - 1) = '\0'; -+ wattron(scr.mw, COLOR_PAIR(color = nickhash(nb))); -+ } + continue; + } + if (n <= 0) { wc = L'?'; n = 1; } if (iswcntrl(wc)) { p += n; - continue; -@@ -648,6 +672,12 @@ tinit(void) +@@ -669,6 +681,12 @@ tinit(void) start_color(); use_default_colors(); init_pair(1, COLOR_WHITE, COLOR_BLACK); @@ -74,3 +55,34 @@ index d1a70aa..7d0f00b 100644 wbkgd(scr.sw, COLOR_PAIR(1)); } } +@@ -722,7 +740,29 @@ tredraw(void) + for (int i = offset; i < (int)c->vis_n && i < offset + height; i++) { + if (c->vis[i].cont) + wmove(scr.mw, getcury(scr.mw), INDENT); +- waddnstr(scr.mw, c->buf + c->vis[i].offset, c->vis[i].len); ++ char *line_ptr = c->buf + c->vis[i].offset; ++ size_t remaining = c->vis[i].len; ++ int color = 0; ++ ++ while (remaining > 0) { ++ char *ctrl = memchr(line_ptr, '\x03', remaining); ++ size_t chunk = ctrl ? (ctrl - line_ptr) : remaining; ++ if (chunk > 0) ++ waddnstr(scr.mw, line_ptr, chunk); ++ if (ctrl) { ++ if (color) { ++ wattroff(scr.mw, COLOR_PAIR(color)); ++ color = 0; ++ } else { ++ color = nickhash(ctrl + 1); ++ wattron(scr.mw, COLOR_PAIR(color)); ++ } ++ chunk += 1; ++ } ++ line_ptr += chunk; ++ remaining -= chunk; ++ } ++ + waddch(scr.mw, '\n'); + } + wnoutrefresh(scr.mw);