summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authornicm <nicm>2019-06-20 11:59:59 +0000
committernicm <nicm>2019-06-20 11:59:59 +0000
commit5f92f92908b81b4ec66682adb84b9ffc8d83c2f7 (patch)
tree1efeb76d391658d00d7b6028ae02b2cf49a5cac6 /options.c
parentc1ede507d954b98a73c40665e7aee6fe5f0c5bce (diff)
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.
Diffstat (limited to 'options.c')
-rw-r--r--options.c100
1 files changed, 66 insertions, 34 deletions
diff --git a/options.c b/options.c
index 3bce6041..bbb6af98 100644
--- a/options.c
+++ b/options.c
@@ -100,7 +100,7 @@ options_parent_table_entry(struct options *oo, const char *s)
if (oo->parent == NULL)
fatalx("no parent options for %s", s);
- o = options_get_only(oo->parent, s);
+ o = options_get(oo->parent, s);
if (o == NULL)
fatalx("%s not in parent options", s);
return (o->tableentry);
@@ -178,6 +178,12 @@ options_free(struct options *oo)
free(oo);
}
+void
+options_set_parent(struct options *oo, struct options *parent)
+{
+ oo->parent = parent;
+}
+
struct options_entry *
options_first(struct options *oo)
{
@@ -545,7 +551,7 @@ options_parse_get(struct options *oo, const char *s, int *idx, int only)
}
char *
-options_match(const char *s, int *idx, int* ambiguous)
+options_match(const char *s, int *idx, int *ambiguous)
{
const struct options_table_entry *oe, *found;
char *name;
@@ -725,70 +731,96 @@ options_set_style(struct options *oo, const char *name, int append,
return (o);
}
-enum options_table_scope
+int
options_scope_from_name(struct args *args, int window,
const char *name, struct cmd_find_state *fs, struct options **oo,
char **cause)
{
- struct session *s = fs->s;
- struct winlink *wl = fs->wl;
- const char *target = args_get(args, 't');
- enum options_table_scope scope;
+ struct session *s = fs->s;
+ struct winlink *wl = fs->wl;
+ struct window_pane *wp = fs->wp;
+ const char *target = args_get(args, 't');
+ const struct options_table_entry *oe;
+ int scope;
if (*name == '@')
return (options_scope_from_flags(args, window, fs, oo, cause));
- 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 {
+ for (oe = options_table; oe->name != NULL; oe++) {
+ if (strcmp(oe->name, name) == 0)
+ break;
+ }
+ if (oe->name == NULL) {
xasprintf(cause, "unknown option: %s", name);
return (OPTIONS_TABLE_NONE);
}
+ scope = oe->scope;
- if (scope == OPTIONS_TABLE_SERVER)
+ switch (scope) {
+ case OPTIONS_TABLE_SERVER:
*oo = global_options;
- else if (scope == OPTIONS_TABLE_SESSION) {
+ break;
+ case OPTIONS_TABLE_SESSION:
if (args_has(args, 'g'))
*oo = global_s_options;
- else if (s == NULL) {
- if (target != NULL)
- xasprintf(cause, "no such session: %s", target);
- else
- xasprintf(cause, "no current session");
- } else
+ else if (s == NULL && target != NULL)
+ xasprintf(cause, "no such session: %s", target);
+ else if (s == NULL)
+ xasprintf(cause, "no current session");
+ else
*oo = s->options;
- } else if (scope == OPTIONS_TABLE_WINDOW) {
+ break;
+ case OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE:
+ if (args_has(args, 'p')) {
+ if (wp == NULL && target != NULL)
+ xasprintf(cause, "no such pane: %s", target);
+ else if (wp == NULL)
+ xasprintf(cause, "no current pane");
+ else
+ *oo = wp->options;
+ break;
+ }
+ scope = OPTIONS_TABLE_WINDOW;
+ /* FALLTHROUGH */
+ case OPTIONS_TABLE_WINDOW:
if (args_has(args, 'g'))
*oo = global_w_options;
- else if (wl == NULL) {
- if (target != NULL)
- xasprintf(cause, "no such window: %s", target);
- else
- xasprintf(cause, "no current window");
- } else
+ else if (wl == NULL && target != NULL)
+ xasprintf(cause, "no such window: %s", target);
+ else if (wl == NULL)
+ xasprintf(cause, "no current window");
+ else
*oo = wl->window->options;
+ break;
}
return (scope);
}
-enum options_table_scope
+int
options_scope_from_flags(struct args *args, int window,
struct cmd_find_state *fs, struct options **oo, char **cause)
{
- struct session *s = fs->s;
- struct winlink *wl = fs->wl;
- const char *target = args_get(args, 't');
+ struct session *s = fs->s;
+ struct winlink *wl = fs->wl;
+ struct window_pane *wp = fs->wp;
+ const char *target = args_get(args, 't');
if (args_has(args, 's')) {
*oo = global_options;
return (OPTIONS_TABLE_SERVER);
}
- if (window || args_has(args, 'w')) {
+ if (args_has(args, 'p')) {
+ if (wp == NULL) {
+ if (target != NULL)
+ xasprintf(cause, "no such pane: %s", target);
+ else
+ xasprintf(cause, "no current pane");
+ return (OPTIONS_TABLE_NONE);
+ }
+ *oo = wp->options;
+ return (OPTIONS_TABLE_PANE);
+ } else if (window || args_has(args, 'w')) {
if (args_has(args, 'g')) {
*oo = global_w_options;
return (OPTIONS_TABLE_WINDOW);