diff options
author | June McEnroe <june@causal.agency> | 2018-08-11 19:30:30 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-08-11 20:02:03 -0400 |
commit | a281f89592cf5531ebf53863768fccd054de252c (patch) | |
tree | 502042617c3909ed5143d3e51562a7314666b250 /tag.c | |
parent | Add term.c for extra terminal features (diff) | |
download | test-a281f89592cf5531ebf53863768fccd054de252c.tar.gz test-a281f89592cf5531ebf53863768fccd054de252c.zip |
Rework UI code for multi-channel
Tags are now permanently assigned (and I'm betting on never needing more than 256 of them) and the UI maps tags to a linked list of views for easy reordering and removal. Currently, views can only be added. Views don't have a topic window until they need one. All UI code wants to be functional reactive. Beeping is temporarily removed until message priorities (status, message, ping) can be added to the UI. At that point spawning notify-send should also be possible. Priorities will also help with unnecessary markers, which will not appear for status messages. The tab system is now used to send QUIT and NICK messages to all the relevant tags. Verbose output now goes to its own tag, and sending to it sends raw IRC. IRC colors are now listed in chat.h and handler functions for numeric replies have real names. The color algorithm now uses a real hash function for hopefully better results. QUIT, PART and KICK messages are scanned for URLs.
Diffstat (limited to 'tag.c')
-rw-r--r-- | tag.c | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/tag.c b/tag.c index 014e84c..397c191 100644 --- a/tag.c +++ b/tag.c @@ -21,57 +21,30 @@ #include "chat.h" -const struct Tag TAG_ALL = { (size_t)-1, NULL }; -const struct Tag TAG_DEFAULT = { 0, "(status)" }; +const struct Tag TAG_NONE = { 0, "" }; +const struct Tag TAG_STATUS = { 1, "(status)" }; +const struct Tag TAG_VERBOSE = { 2, "(irc)" }; static struct { char *name[TAGS_LEN]; size_t len; - size_t gap; } tags = { - .name = { "(status)" }, - .len = 1, - .gap = 1, + .name = { "", "(status)", "(irc)" }, + .len = 3, }; static struct Tag Tag(size_t id) { return (struct Tag) { id, tags.name[id] }; } -struct Tag tagName(const char *name) { +struct Tag tagFor(const char *name) { for (size_t id = 0; id < tags.len; ++id) { - if (!tags.name[id] || strcmp(tags.name[id], name)) continue; + if (strcmp(tags.name[id], name)) continue; return Tag(id); } - return TAG_ALL; -} - -struct Tag tagNum(size_t num) { - if (num < tags.gap) return Tag(num); - num -= tags.gap; - for (size_t id = tags.gap; id < tags.len; ++id) { - if (!tags.name[id]) continue; - if (!num--) return Tag(id); - } - return TAG_ALL; -} - -struct Tag tagFor(const char *name) { - struct Tag tag = tagName(name); - if (tag.name) return tag; - - size_t id = tags.gap; + if (tags.len == TAGS_LEN) return TAG_STATUS; + size_t id = tags.len++; tags.name[id] = strdup(name); if (!tags.name[id]) err(EX_OSERR, "strdup"); - - if (tags.gap == tags.len) { - tags.gap++; - tags.len++; - } else { - for (tags.gap++; tags.gap < tags.len; ++tags.gap) { - if (!tags.name[tags.gap]) break; - } - } - return Tag(id); } |