about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-02 03:27:50 -0500
committerJune McEnroe <june@causal.agency>2020-02-02 03:27:50 -0500
commit8bb9ea7b7ff2e98bbe629f9f2e63f1dcb70250e3 (patch)
tree713c9916a5160ba96204844a8fd70799ded19072
parentImplement window switching and status line (diff)
downloadcatgirl-8bb9ea7b7ff2e98bbe629f9f2e63f1dcb70250e3.tar.gz
catgirl-8bb9ea7b7ff2e98bbe629f9f2e63f1dcb70250e3.zip
Add idColors
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);
er'>2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe