From ab170467a5de233d9ccaba22492eb8324ceedf88 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Fri, 27 Nov 2026 21:34:07 +0100 Subject: [PATCH] Add optional server names to the channel tree --- README.md | 3 +++ irc9.c | 17 ++++++++++++++++- irc9rc-example | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fffaea0..82b6fed 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,9 @@ server irc.example.org 6667 server [port] [ssl|tls] ``` +An optional `name ` line below `server` sets its label in the +channel tree. The label defaults to the hostname. + The port defaults to `6667`. The optional third token `ssl` or `tls` enables TLS; use port `6697` for Libera and OFTC. A `sasl ` line applies to the most recent `server` line and enables SASL PLAIN for that server only. The diff --git a/irc9.c b/irc9.c index 6fb7b7b..420c9e9 100644 --- a/irc9.c +++ b/irc9.c @@ -89,6 +89,7 @@ typedef struct AutojoinChannel { typedef struct Server { char host[HOSTLEN]; + char *name; int port; char nick[NICKLEN]; char user[NICKLEN]; @@ -569,6 +570,19 @@ static void load_config(const char *path) char *save = NULL; key = strtok_r(p, " \t", &save); if (!key) continue; + if (strcasecmp(key, "name") == 0) { + save += strspn(save, " \t"); + size_t len = strlen(save); + while (len && (save[len - 1] == ' ' || save[len - 1] == '\t')) + save[--len] = 0; + if (last && *save) { + free(last->name); + last->name = dupstr(save); + } else { + fprintf(stderr, "irc9: name requires a server and a display name\n"); + } + continue; + } if (strcasecmp(key, "autocommand") == 0) { save += strspn(save, " \t"); if (last && *save && strlen(save) <= MAXLINE - 2 && @@ -2176,7 +2190,7 @@ static void draw_tree(void) terminal_move(y, 1); fputs(selected ? (terminal_color ? "\033[1;4m" : "\033[7m") : "\033[1m", stdout); printf("%c ", s->connected ? '*' : ' '); - terminal_text(s->host, treew - 4); + terminal_text(s->name ? s->name : s->host, treew - 4); fputs("\033[0m", stdout); } y++; @@ -2637,6 +2651,7 @@ int main(int argc, char **argv) free(channel); } #endif + free(s->name); free(s->autocommand); free(s); s = sn; diff --git a/irc9rc-example b/irc9rc-example index 2466a74..4962416 100644 --- a/irc9rc-example +++ b/irc9rc-example @@ -11,10 +11,12 @@ real Armin # user is your account name. An optional autocommand sends one raw IRC command # after registration on the server above it, before startup channel joins. server irc.libera.chat 6697 ssl +# name Libera Chat # sasl armin my-sasl-password # autocommand PRIVMSG NickServ :STATUS armin server irc.oftc.net 6697 ssl +# name OFTC # sasl armin my-sasl-password # autocommand PRIVMSG NickServ :STATUS armin