[PATCH] nick/channel colors: Use reverse video not colors for topic change when disabled

[PATCH] nick/channel colors: Use reverse video not colors for topic change when disabled

From: Klemens Nanni
`-H 0,0`/"hash = 0,0" makes catgirl mostly colorless which is great,
but topic changes still hardcode brown/green colors to show differences
which is usually not desired by users (like me) disabling colors.

Go for a less eye stressing topic change message that shows both old
and new in reverse video with default terminal colors.

This isn't perfect, other parts of catgirl still hardcode colors and
`-H 0,0`/"hash = 0,0" was never meant to disable colors completely, but
topics change often enough that avoiding less readable^Waccessible topic
diffs seems sensible enough.

NB: parseHash() is brittle and "0,0" is not the only value disabling
colors...
---
 chat.h   | 3 +++
 handle.c | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/chat.h b/chat.h
index fadbc30..57fdc62 100644
--- a/chat.h
+++ b/chat.h
@@ -138,6 +138,9 @@ static inline uint idFor(const char *name) {
 
 extern uint32_t hashInit;
 extern uint32_t hashBound;
+static inline bool colorDisabled(void) {
+	return hashInit == 0 && hashBound == 0;
+}
 static inline enum Color hash(const char *str) {
 	if (hashBound < Blue) return Default;
 	if (*str == '~') str++;
diff --git a/handle.c b/handle.c
index 09b28d5..d210aac 100644
--- a/handle.c
+++ b/handle.c
@@ -662,6 +662,11 @@ static void handleTopic(struct Message *msg) {
 	if (swprintf(old, ARRAY_LEN(old), L"%s", prev) < 0) goto plain;
 	if (swprintf(new, ARRAY_LEN(new), L"%s", msg->params[1]) < 0) goto plain;
 
+	if (colorDisabled()) {
+		catf(&cat, "\3%c%ls%c -> %c%ls%c", R, old, R, R, new, R);
+		goto plain;
+	}
+
 	size_t pre;
 	for (pre = 0; old[pre] && new[pre] && old[pre] == new[pre]; ++pre);
 	wchar_t *osuf = &old[wcslen(old)];
-- 
2.31.1

Re: [PATCH] nick/channel colors: Use reverse video not colors for topic change when disabled

From: june
Thanks, applied. Replaced some R’s with O’s to reset any formatting
that might be in the topics.

Re: [PATCH] nick/channel colors: Use reverse video not colors for topic change when disabled

From: Klemens Nanni
To: june
On Tue, May 25, 2021 at 04:29:48PM -0400, june wrote:
> Thanks, applied. Replaced some R’s with O’s to reset any formatting
> that might be in the topics.
Right, R wouldn't suffice; thanks.