summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--chat.c7
-rw-r--r--chat.h47
-rw-r--r--handle.c3
-rw-r--r--ui.c8
4 files changed, 38 insertions, 27 deletions
diff --git a/chat.c b/chat.c
index d4ed31c..b61dd34 100644
--- a/chat.c
+++ b/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;
diff --git a/chat.h b/chat.h
index 9060f29..4ced983 100644
--- a/chat.h
+++ b/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+/"
diff --git a/handle.c b/handle.c
index 609867e..f52f6f9 100644
--- a/handle.c
+++ b/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]
 	);
 }
 
diff --git a/ui.c b/ui.c
index 3ae6592..961e448 100644
--- a/ui.c
+++ b/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);