hirc

IRC client
Log | Files | Refs

commit 7294081ec31678c4e758d9b981ef5db6742dac6c
parent a83272e0a27ba1e4e04725b0923dc802d892ed2c
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 24 Apr 2022 15:04:02 +0100

/toggle command

Diffstat:
Msrc/commands.c | 27+++++++++++++++++++++++++++
Msrc/complete.c | 2+-
Msrc/data/commands.h | 4++++
3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/commands.c b/src/commands.c @@ -704,6 +704,33 @@ command_set) { } COMMAND( +command_toggle) { + struct Config *conf; + char *p; + + if (!str) { + command_toofew("toggle"); + return; + } + if ((p = strrchr(str, ' ')) && *(p+1) == '\0') + *p = '\0'; + if (strchr(str, ' ')) { + command_toomany("toggle"); + return; + } + if (!(conf = config_getp(str))) { + ui_error("no such configuration variable", NULL); + return; + } + if (!conf->valtype == Val_bool) { + ui_error("%s is not a boolean variable", str); + return; + } + + config_setl(conf, !conf->num); +} + +COMMAND( command_format) { char *newstr; int len; diff --git a/src/complete.c b/src/complete.c @@ -234,7 +234,7 @@ getcmd: if (cmd) { if (wcscmp(cmd, L"help") == 0) type = 1; - else if (wcscmp(cmd, L"set") == 0) + else if (wcscmp(cmd, L"set") == 0 || wcscmp(cmd, L"toggle") == 0) type = 2; else if (wcscmp(cmd, L"format") == 0) type = 3; diff --git a/src/data/commands.h b/src/data/commands.h @@ -70,6 +70,7 @@ COMMAND(command_unban); COMMAND(command_query); COMMAND(command_select); COMMAND(command_set); +COMMAND(command_toggle); COMMAND(command_format); COMMAND(command_server); COMMAND(command_bind); @@ -250,6 +251,9 @@ struct Command commands[] = { " /set <variable> string....", "Set a configuration variable.", "Passing only the name prints content.", NULL}}, + {"toggle", command_toggle, 0, { + "usage: /toggle <variable>", + "Toggle a boolean configuration variable on or off.", NULL}}, {"format", command_format, 0, { "usage: /format <format> string...", "Set a formatting variable.",