Add idColors
parent
ec83332e15
commit
8bb9ea7b7f
7
chat.c
7
chat.c
|
@ -29,6 +29,13 @@ char *idNames[IDCap] = {
|
|||
[Debug] = "<debug>",
|
||||
[Network] = "<network>",
|
||||
};
|
||||
|
||||
enum Color idColors[IDCap] = {
|
||||
[None] = Black,
|
||||
[Debug] = Red,
|
||||
[Network] = Gray,
|
||||
};
|
||||
|
||||
size_t idNext = Network + 1;
|
||||
|
||||
struct Self self;
|
||||
|
|
47
chat.h
47
chat.h
|
@ -26,8 +26,21 @@
|
|||
|
||||
typedef unsigned char byte;
|
||||
|
||||
#define B "\2"
|
||||
#define C "\3"
|
||||
#define R "\17"
|
||||
#define V "\26"
|
||||
#define I "\35"
|
||||
#define U "\37"
|
||||
enum Color {
|
||||
White, Black, Blue, Green, Red, Brown, Magenta, Orange,
|
||||
Yellow, LightGreen, Cyan, LightCyan, LightBlue, Pink, Gray, LightGray,
|
||||
Default = 99,
|
||||
};
|
||||
|
||||
enum { None, Debug, Network, IDCap = 256 };
|
||||
extern char *idNames[IDCap];
|
||||
extern enum Color idColors[IDCap];
|
||||
extern size_t idNext;
|
||||
|
||||
static inline size_t idFind(const char *name) {
|
||||
|
@ -36,6 +49,7 @@ static inline size_t idFind(const char *name) {
|
|||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
static inline size_t idFor(const char *name) {
|
||||
size_t id = idFind(name);
|
||||
if (id) return id;
|
||||
|
@ -83,28 +97,6 @@ struct Message {
|
|||
char *params[ParamCap];
|
||||
};
|
||||
|
||||
#define B "\2"
|
||||
#define C "\3"
|
||||
#define R "\17"
|
||||
#define V "\26"
|
||||
#define I "\35"
|
||||
#define U "\37"
|
||||
enum Color {
|
||||
White, Black, Blue, Green, Red, Brown, Magenta, Orange,
|
||||
Yellow, LightGreen, Cyan, LightCyan, LightBlue, Pink, Gray, LightGray,
|
||||
Default = 99,
|
||||
};
|
||||
static inline enum Color 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 % 14;
|
||||
}
|
||||
|
||||
void ircConfig(bool insecure, const char *cert, const char *priv);
|
||||
int ircConnect(const char *host, const char *port);
|
||||
void ircRecv(void);
|
||||
|
@ -140,6 +132,17 @@ void termTitle(const char *title);
|
|||
void termMode(enum TermMode mode, bool set);
|
||||
enum TermEvent termEvent(char ch);
|
||||
|
||||
static inline enum Color 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 % 14;
|
||||
}
|
||||
|
||||
#define BASE64_SIZE(len) (1 + ((len) + 2) / 3 * 4)
|
||||
static const char Base64[64] = {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
|
|
3
handle.c
3
handle.c
|
@ -183,12 +183,13 @@ static void handleJoin(struct Message *msg) {
|
|||
require(msg, true, 1);
|
||||
size_t id = idFor(msg->params[0]);
|
||||
if (self.nick && !strcmp(msg->nick, self.nick)) {
|
||||
idColors[id] = hash(msg->params[0]);
|
||||
uiShowID(id);
|
||||
}
|
||||
uiFormat(
|
||||
id, Cold, tagTime(msg),
|
||||
C"%02d%s"C" arrives in "C"%02d%s"C,
|
||||
hash(msg->user), msg->nick, hash(idNames[id]), idNames[id]
|
||||
hash(msg->user), msg->nick, idColors[id], idNames[id]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
8
ui.c
8
ui.c
|
@ -268,15 +268,15 @@ static void statusUpdate(void) {
|
|||
const struct Window *window;
|
||||
for (num = 0, window = windows.head; window; ++num, window = window->next) {
|
||||
if (!window->unread && window != windows.active) continue;
|
||||
enum Color color = hash(idNames[window->id]); // FIXME: queries.
|
||||
int unread;
|
||||
char buf[256];
|
||||
snprintf(
|
||||
buf, sizeof(buf), C"%d%s %d %s %n("C"%02d%d"C"%d) ",
|
||||
color, (window == windows.active ? V : ""),
|
||||
idColors[window->id], (window == windows.active ? V : ""),
|
||||
num, idNames[window->id],
|
||||
&unread, (window->heat > Warm ? White : color), window->unread,
|
||||
color
|
||||
&unread, (window->heat > Warm ? White : idColors[window->id]),
|
||||
window->unread,
|
||||
idColors[window->id]
|
||||
);
|
||||
if (!window->unread) buf[unread] = '\0';
|
||||
styleAdd(status, buf);
|
||||
|
|
Loading…
Reference in New Issue