diff options
-rw-r--r-- | chat.h | 25 | ||||
-rw-r--r-- | handle.c | 24 | ||||
-rw-r--r-- | input.c | 4 | ||||
-rw-r--r-- | tag.c | 15 | ||||
-rw-r--r-- | ui.c | 7 |
5 files changed, 43 insertions, 32 deletions
diff --git a/chat.h b/chat.h index 452470d..f3a102c 100644 --- a/chat.h +++ b/chat.h @@ -52,18 +52,6 @@ void eventWait(const char *argv[static 2]); void eventPipe(const char *argv[static 2]); noreturn void eventLoop(void); -struct Tag { - size_t id; - const char *name; -}; - -enum { TagsLen = 256 }; -const struct Tag TagNone; -const struct Tag TagStatus; -const struct Tag TagRaw; -struct Tag tagFind(const char *name); -struct Tag tagFor(const char *name); - enum IRCColor { IRCWhite, IRCBlack, @@ -92,6 +80,19 @@ enum { IRCUnderline = 037, }; +struct Tag { + size_t id; + const char *name; + enum IRCColor color; +}; + +enum { TagsLen = 256 }; +const struct Tag TagNone; +const struct Tag TagStatus; +const struct Tag TagRaw; +struct Tag tagFind(const char *name); +struct Tag tagFor(const char *name, enum IRCColor color); + struct Format { const wchar_t *str; size_t len; diff --git a/handle.c b/handle.c index 5281d8f..579c073 100644 --- a/handle.c +++ b/handle.c @@ -214,7 +214,7 @@ static void handleErrorNoSuchNick(char *prefix, char *params) { static void handleJoin(char *prefix, char *params) { char *nick, *user, *chan; parse(prefix, &nick, &user, NULL, params, 1, 0, &chan); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); if (!strcmp(nick, self.nick)) { tabTouch(TagNone, chan); @@ -234,7 +234,7 @@ static void handleJoin(char *prefix, char *params) { static void handlePart(char *prefix, char *params) { char *nick, *user, *chan, *mesg; parse(prefix, &nick, &user, NULL, params, 1, 1, &chan, &mesg); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); if (!strcmp(nick, self.nick)) { tabClear(tag); @@ -263,7 +263,7 @@ static void handlePart(char *prefix, char *params) { static void handleKick(char *prefix, char *params) { char *nick, *user, *chan, *kick, *mesg; parse(prefix, &nick, &user, NULL, params, 2, 1, &chan, &kick, &mesg); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); bool kicked = !strcmp(kick, self.nick); if (kicked) { @@ -324,7 +324,7 @@ static void handleQuit(char *prefix, char *params) { static void handleReplyTopic(char *prefix, char *params) { char *chan, *topic; parse(prefix, NULL, NULL, NULL, params, 3, 0, NULL, &chan, &topic); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); urlScan(tag, topic); uiFmt( @@ -338,7 +338,7 @@ static void handleReplyTopic(char *prefix, char *params) { static void handleTopic(char *prefix, char *params) { char *nick, *user, *chan, *topic; parse(prefix, &nick, &user, NULL, params, 2, 0, &chan, &topic); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); if (strcmp(nick, self.nick)) tabTouch(tag, nick); @@ -369,7 +369,7 @@ static void handleReplyWho(char *prefix, char *params) { params, 6, 0, NULL, &chan, &user, NULL, NULL, &nick ); if (user[0] == '~') user = &user[1]; - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); tabAdd(tag, nick); @@ -385,7 +385,7 @@ static void handleReplyWho(char *prefix, char *params) { static void handleReplyEndOfWho(char *prefix, char *params) { char *chan; parse(prefix, NULL, NULL, NULL, params, 2, 0, NULL, &chan); - struct Tag tag = tagFor(chan); + struct Tag tag = tagFor(chan, formatColor(chan)); uiFmt( tag, UICold, @@ -441,7 +441,9 @@ static void handlePrivmsg(char *prefix, char *params) { char *nick, *user, *chan, *mesg; parse(prefix, &nick, &user, NULL, params, 2, 0, &chan, &mesg); bool direct = !strcmp(chan, self.nick); - struct Tag tag = (direct ? tagFor(nick) : tagFor(chan)); + struct Tag tag = direct + ? tagFor(nick, formatColor(user)) + : tagFor(chan, formatColor(chan)); if (mesg[0] == '\1') { handleCTCP(tag, nick, user, mesg); return; @@ -466,7 +468,11 @@ static void handleNotice(char *prefix, char *params) { char *nick, *user, *chan, *mesg; parse(prefix, &nick, &user, NULL, params, 2, 0, &chan, &mesg); struct Tag tag = TagStatus; - if (user) tag = (strcmp(chan, self.nick) ? tagFor(chan) : tagFor(nick)); + if (user) { + tag = strcmp(chan, self.nick) + ? tagFor(chan, formatColor(chan)) + : tagFor(nick, formatColor(user)); + } if (strcmp(nick, self.nick)) tabTouch(tag, nick); diff --git a/input.c b/input.c index 45de9f1..f570dee 100644 --- a/input.c +++ b/input.c @@ -66,8 +66,8 @@ static void inputQuery(struct Tag tag, char *params) { char *nick = strsep(¶ms, " "); if (nick) { tabTouch(TagNone, nick); - uiShowTag(tagFor(nick)); - logReplay(tagFor(nick)); + uiShowTag(tagFor(nick, IRCDefault)); + logReplay(tagFor(nick, IRCDefault)); } else { uiLog(tag, UIHot, L"/query requires a nickname"); } diff --git a/tag.c b/tag.c index cae5f03..13f59d0 100644 --- a/tag.c +++ b/tag.c @@ -23,30 +23,33 @@ static struct { char *name[TagsLen]; + enum IRCColor color[TagsLen]; size_t len; } tags = { .name = { "<none>", "<status>", "<raw>" }, + .color = { IRCBlack, IRCDefault, IRCRed }, .len = 3, }; -const struct Tag TagNone = { 0, "<none>" }; -const struct Tag TagStatus = { 1, "<status>" }; -const struct Tag TagRaw = { 2, "<raw>" }; +const struct Tag TagNone = { 0, "<none>", IRCBlack }; +const struct Tag TagStatus = { 1, "<status>", IRCDefault }; +const struct Tag TagRaw = { 2, "<raw>", IRCRed }; struct Tag tagFind(const char *name) { for (size_t id = 0; id < tags.len; ++id) { if (strcmp(tags.name[id], name)) continue; - return (struct Tag) { id, tags.name[id] }; + return (struct Tag) { id, tags.name[id], tags.color[id] }; } return TagNone; } -struct Tag tagFor(const char *name) { +struct Tag tagFor(const char *name, enum IRCColor color) { struct Tag tag = tagFind(name); if (tag.id != TagNone.id) return tag; if (tags.len == TagsLen) return TagStatus; size_t id = tags.len++; tags.name[id] = strdup(name); if (!tags.name[id]) err(EX_OSERR, "strdup"); - return (struct Tag) { id, tags.name[id] }; + tags.color[id] = color; + return (struct Tag) { id, tags.name[id], color }; } diff --git a/ui.c b/ui.c index ab519b6..ffb2916 100644 --- a/ui.c +++ b/ui.c @@ -335,10 +335,11 @@ static void uiStatus(void) { int unread; wchar_t *str; int len = aswprintf( - &str, L"%c %d %s %n(\3%02d%u\3) ", - (windows.active == win ? IRCReverse : IRCReset), + &str, L"%c\3%d %d %s %n(\3%02d%u\3%d) ", + (windows.active == win ? IRCReverse : IRCReset), win->tag.color, num, win->tag.name, - &unread, (win->hot ? IRCYellow : IRCDefault), win->unread + &unread, (win->hot ? IRCWhite : win->tag.color), win->unread, + win->tag.color ); if (len < 0) err(EX_OSERR, "aswprintf"); if (!win->unread) str[unread] = L'\0'; |