From 5390b3022cb208fa3518c0faedb48325a4ddfbe6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Fri, 27 Nov 2026 21:47:51 +0100 Subject: [PATCH] Allow custom TUI accent colors --- README.md | 3 +++ irc9.c | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 82b6fed..1922a92 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ make ``` `-s` and `--silent` hide JOIN and QUIT notices in channel windows. +Use `-c RRGGBB` or `--color RRGGBB` to replace the default cyan accent on +the channel tree and divider. For example, `./irc9 --color FF8800` uses +orange on terminals with true-color support. With no config path, irc9 looks next to the executable, in this order: `irc9rc`, `config`, then `~/.irc9rc`. Paths are relative to the binary, not to diff --git a/irc9.c b/irc9.c index 420c9e9..1104d5a 100644 --- a/irc9.c +++ b/irc9.c @@ -153,6 +153,7 @@ static int treew = TREEW, mainh = 1; static struct termios saved_terminal; static int terminal_active; static int terminal_color; +static long accent_color = -1; enum { KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT, @@ -2163,10 +2164,21 @@ static void push_wrapped(char **rows, int *nr, int maxrows, const char *s, int w free(copy); } +static void terminal_accent(void) +{ + if (!terminal_color) return; + if (accent_color < 0) { + fputs("\033[36m", stdout); + } else { + printf("\033[38;2;%ld;%ld;%ldm", (accent_color >> 16) & 255, + (accent_color >> 8) & 255, accent_color & 255); + } +} + static void draw_tree(void) { if (treew < 2 || mainh < 2) return; - if (terminal_color) fputs("\033[36m", stdout); + terminal_accent(); terminal_move(1, 0); putchar('/'); terminal_repeat('-', treew - 2); @@ -2201,7 +2213,7 @@ static void draw_tree(void) else snprintf(label, sizeof label, "%s", w->name); if (treew > 5) { terminal_move(y, 2); - if (terminal_color) fputs("\033[36m", stdout); + terminal_accent(); fputs(w->next ? "|-" : "\\-", stdout); fputs("\033[0m", stdout); if (w == curwin) fputs(terminal_color ? "\033[1;4m" : "\033[7m", stdout); @@ -2335,7 +2347,7 @@ static void draw_input(void) { if (lines < 4) return; terminal_move(lines - 3, 0); - if (terminal_color) fputs("\033[36m", stdout); + terminal_accent(); terminal_repeat('-', cols); fputs("\033[0m", stdout); fputs(terminal_color ? "\033[1m" : "\033[7m", stdout); @@ -2537,10 +2549,17 @@ int main(int argc, char **argv) options = 0; } else if (options && (strcmp(arg, "-s") == 0 || strcmp(arg, "--silent") == 0)) { silent = 1; + } else if (options && (strcmp(arg, "-c") == 0 || strcmp(arg, "--color") == 0)) { + if (++i == argc || strlen(argv[i]) != 6 || + strspn(argv[i], "0123456789abcdefABCDEF") != 6) { + fprintf(stderr, "irc9: %s requires a six-digit hexadecimal color (RRGGBB)\n", arg); + return 1; + } + accent_color = strtol(argv[i], NULL, 16); } else if (!path && (!options || arg[0] != '-' || arg[1] == 0)) { path = arg; } else { - fprintf(stderr, "usage: %s [-s|--silent] [config]\n", argv[0]); + fprintf(stderr, "usage: %s [-s|--silent] [-c|--color RRGGBB] [config]\n", argv[0]); return 1; } }