From cd1fc42df6d1bacac4f617e031c279ba31bc0632 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 07:10:56 +0000 Subject: Add a -A flag to show-options to show parent options as well. --- cmd-show-options.c | 78 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 25 deletions(-) (limited to 'cmd-show-options.c') diff --git a/cmd-show-options.c b/cmd-show-options.c index 6e3eca0d..3c5b6d47 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -31,16 +31,16 @@ static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); static void cmd_show_options_print(struct cmd *, struct cmdq_item *, - struct options_entry *, int); + struct options_entry *, int, int); static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, - struct options *); + enum options_table_scope, struct options *); const struct cmd_entry cmd_show_options_entry = { .name = "show-options", .alias = "show", - .args = { "gHqst:vw", 0, 1 }, - .usage = "[-gHqsvw] [-t target-session|target-window] [option]", + .args = { "AgHqst:vw", 0, 1 }, + .usage = "[-AgHqsvw] [-t target-session|target-window] [option]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, @@ -86,7 +86,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) enum options_table_scope scope; char *argument, *name = NULL, *cause; const char *target; - int window, idx, ambiguous; + int window, idx, ambiguous, parent; struct options_entry *o; window = (self->entry == &cmd_show_window_options_entry); @@ -99,7 +99,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) free(cause); return (CMD_RETURN_ERROR); } - return (cmd_show_options_all(self, item, oo)); + return (cmd_show_options_all(self, item, scope, oo)); } argument = format_single(item, args->argv[0], c, s, wl, NULL); @@ -164,8 +164,13 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) goto fail; } o = options_get_only(oo, name); + if (args_has(args, 'A') && o == NULL) { + o = options_get(oo, name); + parent = 1; + } else + parent = 0; if (o != NULL) - cmd_show_options_print(self, item, o, idx); + cmd_show_options_print(self, item, o, idx, parent); free(name); free(argument); @@ -179,7 +184,7 @@ fail: static void cmd_show_options_print(struct cmd *self, struct cmdq_item *item, - struct options_entry *o, int idx) + struct options_entry *o, int idx, int parent) { struct options_array_item *a; const char *name = options_name(o); @@ -198,7 +203,8 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item, } while (a != NULL) { idx = options_array_item_index(a); - cmd_show_options_print(self, item, o, idx); + cmd_show_options_print(self, item, o, idx, + parent); a = options_array_next(a); } return; @@ -210,10 +216,17 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item, cmdq_print(item, "%s", value); else if (options_isstring(o)) { escaped = args_escape(value); - cmdq_print(item, "%s %s", name, escaped); + if (parent) + cmdq_print(item, "%s* %s", name, escaped); + else + cmdq_print(item, "%s %s", name, escaped); free(escaped); - } else - cmdq_print(item, "%s %s", name, value); + } else { + if (parent) + cmdq_print(item, "%s* %s", name, value); + else + cmdq_print(item, "%s %s", name, value); + } free(value); free(tmp); @@ -221,39 +234,54 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item, static enum cmd_retval cmd_show_options_all(struct cmd *self, struct cmdq_item *item, - struct options *oo) + enum options_table_scope scope, struct options *oo) { + const struct options_table_entry *oe; struct options_entry *o; struct options_array_item *a; u_int idx; - const struct options_table_entry *oe; + int parent; + + for (oe = options_table; oe->name != NULL; oe++) { + if (oe->scope != scope) + continue; - o = options_first(oo); - while (o != NULL) { - oe = options_table_entry(o); if ((self->entry != &cmd_show_hooks_entry && !args_has(self->args, 'H') && oe != NULL && (oe->flags & OPTIONS_TABLE_IS_HOOK)) || (self->entry == &cmd_show_hooks_entry && (oe == NULL || - (~oe->flags & OPTIONS_TABLE_IS_HOOK)))) { - o = options_next(o); + (~oe->flags & OPTIONS_TABLE_IS_HOOK)))) continue; - } + + o = options_get_only(oo, oe->name); + if (o == NULL) { + if (!args_has(self->args, 'A')) + continue; + o = options_get(oo, oe->name); + if (o == NULL) + continue; + parent = 1; + } else + parent = 0; + if (!options_isarray(o)) - cmd_show_options_print(self, item, o, -1); + cmd_show_options_print(self, item, o, -1, parent); else if ((a = options_array_first(o)) == NULL) { - if (!args_has(self->args, 'v')) - cmdq_print(item, "%s", options_name(o)); + if (!args_has(self->args, 'v')) { + if (parent) + cmdq_print(item, "%s*", options_name(o)); + else + cmdq_print(item, "%s", options_name(o)); + } } else { while (a != NULL) { idx = options_array_item_index(a); - cmd_show_options_print(self, item, o, idx); + cmd_show_options_print(self, item, o, idx, parent); a = options_array_next(a); } } - o = options_next(o); } return (CMD_RETURN_NORMAL); } -- cgit From c1ede507d954b98a73c40665e7aee6fe5f0c5bce Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 07:41:29 +0000 Subject: Add a helper function to work out option table from name. --- cmd-show-options.c | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) (limited to 'cmd-show-options.c') diff --git a/cmd-show-options.c b/cmd-show-options.c index 3c5b6d47..109c6c52 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -85,11 +85,11 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) struct options *oo; enum options_table_scope scope; char *argument, *name = NULL, *cause; - const char *target; int window, idx, ambiguous, parent; struct options_entry *o; window = (self->entry == &cmd_show_window_options_entry); + if (args->argc == 0) { scope = options_scope_from_flags(args, window, fs, &oo, &cause); if (scope == OPTIONS_TABLE_NONE) { @@ -113,49 +113,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "invalid option: %s", argument); goto fail; } - if (*name == '@') - scope = options_scope_from_flags(args, window, fs, &oo, &cause); - else { - if (options_get_only(global_options, name) != NULL) - scope = OPTIONS_TABLE_SERVER; - else if (options_get_only(global_s_options, name) != NULL) - scope = OPTIONS_TABLE_SESSION; - else if (options_get_only(global_w_options, name) != NULL) - scope = OPTIONS_TABLE_WINDOW; - else { - scope = OPTIONS_TABLE_NONE; - xasprintf(&cause, "unknown option: %s", argument); - } - if (scope == OPTIONS_TABLE_SERVER) - oo = global_options; - else if (scope == OPTIONS_TABLE_SESSION) { - if (args_has(self->args, 'g')) - oo = global_s_options; - else if (s == NULL) { - target = args_get(args, 't'); - if (target != NULL) { - cmdq_error(item, "no such session: %s", - target); - } else - cmdq_error(item, "no current session"); - goto fail; - } else - oo = s->options; - } else if (scope == OPTIONS_TABLE_WINDOW) { - if (args_has(self->args, 'g')) - oo = global_w_options; - else if (wl == NULL) { - target = args_get(args, 't'); - if (target != NULL) { - cmdq_error(item, "no such window: %s", - target); - } else - cmdq_error(item, "no current window"); - goto fail; - } else - oo = wl->window->options; - } - } + scope = options_scope_from_name(args, window, name, fs, &oo, &cause); if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) goto fail; -- cgit From 5f92f92908b81b4ec66682adb84b9ffc8d83c2f7 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 11:59:59 +0000 Subject: Add a per-pane option set. Pane options inherit from window options (so there should be no change to existing behaviour) and are set and shown with set-option -p and show-options -p. Change remain-on-exit and window-style/window-active-style to be pane options (some others will be changed later). This makes select-pane -P and -g unnecessary so no longer document them (they still work) and no longer document set-window-option and show-window-options in favour of set-option -w and show-options -w. --- cmd-show-options.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'cmd-show-options.c') diff --git a/cmd-show-options.c b/cmd-show-options.c index 109c6c52..5b22b8bd 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -33,16 +33,16 @@ static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); static void cmd_show_options_print(struct cmd *, struct cmdq_item *, struct options_entry *, int, int); static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, - enum options_table_scope, struct options *); + int, struct options *); const struct cmd_entry cmd_show_options_entry = { .name = "show-options", .alias = "show", - .args = { "AgHqst:vw", 0, 1 }, - .usage = "[-AgHqsvw] [-t target-session|target-window] [option]", + .args = { "AgHpqst:vw", 0, 1 }, + .usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]", - .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, + .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .flags = CMD_AFTERHOOK, .exec = cmd_show_options_exec @@ -83,9 +83,8 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct options *oo; - enum options_table_scope scope; char *argument, *name = NULL, *cause; - int window, idx, ambiguous, parent; + int window, idx, ambiguous, parent, scope; struct options_entry *o; window = (self->entry == &cmd_show_window_options_entry); @@ -191,17 +190,18 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item, } static enum cmd_retval -cmd_show_options_all(struct cmd *self, struct cmdq_item *item, - enum options_table_scope scope, struct options *oo) +cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope, + struct options *oo) { const struct options_table_entry *oe; struct options_entry *o; struct options_array_item *a; + const char *name; u_int idx; int parent; for (oe = options_table; oe->name != NULL; oe++) { - if (oe->scope != scope) + if (~oe->scope & scope) continue; if ((self->entry != &cmd_show_hooks_entry && @@ -228,15 +228,17 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item, cmd_show_options_print(self, item, o, -1, parent); else if ((a = options_array_first(o)) == NULL) { if (!args_has(self->args, 'v')) { + name = options_name(o); if (parent) - cmdq_print(item, "%s*", options_name(o)); + cmdq_print(item, "%s*", name); else - cmdq_print(item, "%s", options_name(o)); + cmdq_print(item, "%s", name); } } else { while (a != NULL) { idx = options_array_item_index(a); - cmd_show_options_print(self, item, o, idx, parent); + cmd_show_options_print(self, item, o, idx, + parent); a = options_array_next(a); } } -- cgit From c1573727f0ea1d8a2530edc1a7848d9aa1d6f590 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 13:39:17 +0000 Subject: Still need to walk the options tree for user options. --- cmd-show-options.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmd-show-options.c') diff --git a/cmd-show-options.c b/cmd-show-options.c index 5b22b8bd..0b9eb096 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -200,6 +200,12 @@ cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope, u_int idx; int parent; + o = options_first(oo); + while (o != NULL) { + if (options_table_entry(o) == NULL) + cmd_show_options_print(self, item, o, -1, 0); + o = options_next(o); + } for (oe = options_table; oe->name != NULL; oe++) { if (~oe->scope & scope) continue; -- cgit