Allow custom TUI accent colors
This commit is contained in:
parent
68246b1421
commit
5390b3022c
2 changed files with 26 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
27
irc9.c
27
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue