changeset 35:688182a92f0e

nirc: add chantypes and don't draw nicklist on queries
author David Demelier <markand@malikania.fr>
date Wed, 11 Mar 2020 20:05:00 +0100
parents aeeddb9ce9c9
children eb346ae781a8
files server.c server.h ui.c
diffstat 3 files changed, 36 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/server.c	Tue Mar 10 20:30:00 2020 +0100
+++ b/server.c	Wed Mar 11 20:05:00 2020 +0100
@@ -108,6 +108,15 @@
 	return;
 }
 
+static void
+handle_support_chantypes(struct server *s, const char *value)
+{
+	assert(s);
+	assert(value);
+
+	snprintf(s->chantypes, sizeof (s->chantypes), "%s", value);
+}
+
 /*
  * 0      1           2               LAST
  * prefix VAR1=value1 VAR2=value2 ... :are supported on this server
@@ -127,6 +136,8 @@
 
 		if (strcmp(key, "PREFIX") == 0)
 			handle_support_prefix(s, value);
+		if (strcmp(key, "CHANTYPES") == 0)
+			handle_support_chantypes(s, value);
 	}
 }
 
--- a/server.h	Tue Mar 10 20:30:00 2020 +0100
+++ b/server.h	Wed Mar 11 20:05:00 2020 +0100
@@ -120,6 +120,7 @@
 #endif
 
 	/* IRC server information. */
+	char chantypes[8];                      /*!< (RO) Channel types (prefixes). */
 	struct server_prefix prefixes[16];      /*!< (RO) Prefixes. */
 	struct journal journal;                 /*!< (RW, owned) Server journal log. */
 };
--- a/ui.c	Tue Mar 10 20:30:00 2020 +0100
+++ b/ui.c	Wed Mar 11 20:05:00 2020 +0100
@@ -19,6 +19,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <math.h>
+#include <string.h>
 
 #include <ncurses.h>
 
@@ -75,6 +76,23 @@
 	struct journal journal;
 } ui;
 
+static bool
+is_query(const struct server *s, const struct channel *ch)
+{
+	assert(s);
+	assert(ch);
+
+	const char *prefixes = "#&";
+
+	/*
+	 * Use RFC1459 if not filled in s->chantypes as sane defaults.
+	 */
+	if (s->chantypes[0])
+		prefixes = s->chantypes;
+
+	return strpbrk(ch->name, prefixes) == NULL;
+}
+
 /* {{{ Sidebar */
 
 enum tree_item_type {
@@ -433,18 +451,15 @@
 	WINDOW *f = widgets[UI_ELT_NICKLIST].frame;
 	struct tree_item *ti = &sidebar.items[sidebar.sel];
 
+	if (ti->type != TREE_CHAN || is_query(ui_selected_server(), ti->c.chan))
+		return;
+
 	wmove(f, 0, 0);
 	werase(f);
 	wvline(f, ACS_VLINE, LINES - 3);
 
-	switch (ti->type) {
-	case TREE_CHAN:
-		for (size_t i = 0; i < ti->c.chan->nicksz; ++i)
-			mvwprintw(f, i, 1, "%s\n", ti->c.chan->nicks[i]);
-		break;
-	default:
-		break;
-	}
+	for (size_t i = 0; i < ti->c.chan->nicksz; ++i)
+		mvwprintw(f, i, 1, "%s\n", ti->c.chan->nicks[i]);
 
 	wrefresh(f);
 }
@@ -736,6 +751,7 @@
 void
 ui_refresh(void)
 {
+	clear();
 	refresh();
 
 	for (int i = 0; i < UI_ELT_LAST; ++i)