summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-04-24 21:38:19 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-04-24 21:38:19 +0000
commita27ec956eb181533b8a9b5a2380a9bab1ec5d2e4 (patch)
tree719bca8fb1c2c302c1bf3b454bb9d9ba63073d0f
parent5bc9dd2316430a466195cd17b86750f5eb4727b9 (diff)
Allow choice options (multiple states) to be toggled between states 0
and 1.
-rw-r--r--usr.bin/tmux/cmd-set-option.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index f18b5b78557..52f8ebcdc4b 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.72 2015/04/22 15:30:11 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.73 2015/04/24 21:38:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -289,9 +289,15 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
{
struct options_entry *o;
- if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
- cmdq_error(cmdq, "empty value");
- return (-1);
+ switch (oe->type) {
+ case OPTIONS_TABLE_FLAG:
+ case OPTIONS_TABLE_CHOICE:
+ break;
+ default:
+ if (value == NULL) {
+ cmdq_error(cmdq, "empty value");
+ return (-1);
+ }
}
o = NULL;
@@ -455,21 +461,27 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq,
const char **choicep;
int n, choice = -1;
- n = 0;
- for (choicep = oe->choices; *choicep != NULL; choicep++) {
- n++;
- if (strncmp(*choicep, value, strlen(value)) != 0)
- continue;
-
- if (choice != -1) {
- cmdq_error(cmdq, "ambiguous value: %s", value);
+ if (value == NULL) {
+ choice = options_get_number(oo, oe->name);
+ if (choice < 2)
+ choice = !choice;
+ } else {
+ n = 0;
+ for (choicep = oe->choices; *choicep != NULL; choicep++) {
+ n++;
+ if (strncmp(*choicep, value, strlen(value)) != 0)
+ continue;
+
+ if (choice != -1) {
+ cmdq_error(cmdq, "ambiguous value: %s", value);
+ return (NULL);
+ }
+ choice = n - 1;
+ }
+ if (choice == -1) {
+ cmdq_error(cmdq, "unknown value: %s", value);
return (NULL);
}
- choice = n - 1;
- }
- if (choice == -1) {
- cmdq_error(cmdq, "unknown value: %s", value);
- return (NULL);
}
return (options_set_number(oo, oe->name, choice));