colornames.diff (1785B)
1 cio.c | 34 ++++++++++++++++++++++++++++++++-- 2 1 file changed, 32 insertions(+), 2 deletions(-) 3 4 diff --git a/cio.c b/cio.c 5 index d1a70aa..7d0f00b 100644 6 --- a/cio.c 7 +++ b/cio.c 8 @@ -51,8 +51,8 @@ 9 #define INDENT 23 10 #define TABSTOP 8 11 #define DATEFMT "%H:%M" 12 -#define PFMT " %-12s < %s" 13 -#define PFMTHIGH "> %-12s < %s" 14 +#define PFMT " \x03%-12s\x03 < %s" 15 +#define PFMTHIGH "> \x03%-12s\x03 < %s" 16 #define SRV "irc.oftc.net" 17 #define PORT "6697" 18 19 @@ -153,6 +153,14 @@ empty(const char *str) { 20 return (str == NULL || str[0] == '\0'); 21 } 22 23 +static int 24 +nickhash(const char *s) 25 +{ 26 + unsigned int h = 5381; 27 + while (*s) h = ((h << 5) + h) + (*s++); 28 + return (h % 6) + 2; /* Use pairs 2-7 */ 29 +} 30 + 31 static void 32 sndf(const char *fmt, ...) 33 { 34 @@ -340,6 +348,7 @@ pushl(char *p, char *e) 35 wchar_t wc; 36 int n, cl; 37 cchar_t cc; 38 + int color = 0; 39 char *eol = memchr(p, '\n', e - p); 40 41 if (!eol) eol = e; 42 @@ -349,6 +358,21 @@ pushl(char *p, char *e) 43 mbtowc(NULL, NULL, 0); 44 wc = L'?'; n = 1; 45 } 46 + if (wc == L'\x03') { 47 + p += n; 48 + if (color) { 49 + wattroff(scr.mw, COLOR_PAIR(color)); 50 + color = 0; 51 + continue; 52 + } 53 + char nb[64]; 54 + char *found = memccpy(nb, p, '\x03', sizeof(nb) - 1); 55 + if (found) { 56 + *(found - 1) = '\0'; 57 + wattron(scr.mw, COLOR_PAIR(color = nickhash(nb))); 58 + } 59 + continue; 60 + } 61 if (iswcntrl(wc)) { 62 p += n; 63 continue; 64 @@ -648,6 +672,12 @@ tinit(void) 65 start_color(); 66 use_default_colors(); 67 init_pair(1, COLOR_WHITE, COLOR_BLACK); 68 + init_pair(2, COLOR_RED, -1); 69 + init_pair(3, COLOR_GREEN, -1); 70 + init_pair(4, COLOR_YELLOW, -1); 71 + init_pair(5, COLOR_BLUE, -1); 72 + init_pair(6, COLOR_MAGENTA, -1); 73 + init_pair(7, COLOR_CYAN, -1); 74 wbkgd(scr.sw, COLOR_PAIR(1)); 75 } 76 }