From f03b61131b3407929fea187a309fb336017791d1 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 16 May 2020 15:01:30 +0000 Subject: Drop having a separate type for style options and make them all strings, which allows formats to be expanded. Any styles without a '#{' are still validated when they are set but any with a '#{' are not. Formats are not expanded usefully in many cases yet, that will be changed later. To make this work, a few other changes: - set-option -a with a style option automatically appends a ",". - OSC 10 and 11 don't set the window-style option anymore, instead the fg and bg are stored in the pane struct and act as the defaults that can be overridden by window-style. - status-fg and -bg now override status-style instead of trying to keep them in sync. --- cmd-set-option.c | 57 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'cmd-set-option.c') diff --git a/cmd-set-option.c b/cmd-set-option.c index 1752d093..e04aa7ff 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -93,7 +93,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) char *name, *argument, *value = NULL, *cause; int window, idx, already, error, ambiguous; int scope; - struct style *sy; window = (cmd_get_entry(self) == &cmd_set_window_option_entry); @@ -232,16 +231,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) tty_keys_build(&loop->tty); } } - if (strcmp(name, "status-fg") == 0 || strcmp(name, "status-bg") == 0) { - sy = options_get_style(oo, "status-style"); - sy->gc.fg = options_get_number(oo, "status-fg"); - sy->gc.bg = options_get_number(oo, "status-bg"); - } - if (strcmp(name, "status-style") == 0) { - sy = options_get_style(oo, "status-style"); - options_set_number(oo, "status-fg", sy->gc.fg); - options_set_number(oo, "status-bg", sy->gc.bg); - } if (strcmp(name, "status") == 0 || strcmp(name, "status-interval") == 0) status_timer_start_all(); @@ -282,6 +271,29 @@ fail: return (CMD_RETURN_ERROR); } +static int +cmd_set_option_check_string(const struct options_table_entry *oe, + const char *value, char **cause) +{ + struct style sy; + + if (strcmp(oe->name, "default-shell") == 0 && !checkshell(value)) { + xasprintf(cause, "not a suitable shell: %s", value); + return (-1); + } + if (oe->pattern != NULL && fnmatch(oe->pattern, value, 0) != 0) { + xasprintf(cause, "value is invalid: %s", value); + return (-1); + } + if ((oe->flags & OPTIONS_TABLE_IS_STYLE) && + strstr(value, "#{") == NULL && + style_parse(&sy, &grid_default_cell, value) != 0) { + xasprintf(cause, "invalid style: %s", value); + return (-1); + } + return (0); +} + static int cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, struct options_entry *parent, const char *value) @@ -289,10 +301,9 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, const struct options_table_entry *oe; struct args *args = cmd_get_args(self); int append = args_has(args, 'a'); - struct options_entry *o; long long number; const char *errstr, *new; - char *old; + char *old, *cause; key_code key; oe = options_table_entry(parent); @@ -308,17 +319,12 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, old = xstrdup(options_get_string(oo, oe->name)); options_set_string(oo, oe->name, append, "%s", value); new = options_get_string(oo, oe->name); - if (strcmp(oe->name, "default-shell") == 0 && - !checkshell(new)) { - options_set_string(oo, oe->name, 0, "%s", old); - free(old); - cmdq_error(item, "not a suitable shell: %s", value); - return (-1); - } - if (oe->pattern != NULL && fnmatch(oe->pattern, new, 0) != 0) { + if (cmd_set_option_check_string(oe, new, &cause) != 0) { + cmdq_error(item, "%s", cause); + free(cause); + options_set_string(oo, oe->name, 0, "%s", old); free(old); - cmdq_error(item, "value is invalid: %s", value); return (-1); } free(old); @@ -350,13 +356,6 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, return (cmd_set_option_flag(item, oe, oo, value)); case OPTIONS_TABLE_CHOICE: return (cmd_set_option_choice(item, oe, oo, value)); - case OPTIONS_TABLE_STYLE: - o = options_set_style(oo, oe->name, append, value); - if (o == NULL) { - cmdq_error(item, "bad style: %s", value); - return (-1); - } - return (0); case OPTIONS_TABLE_COMMAND: break; } -- cgit From d67245c734c9c600ad6d186570a1230aa21b80c8 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 16 May 2020 16:02:24 +0000 Subject: Add a customize mode where keys and options may be browsed and changed, includes adding a brief description of each option. Bound to "C" by default. --- cmd-set-option.c | 216 +++---------------------------------------------------- 1 file changed, 10 insertions(+), 206 deletions(-) (limited to 'cmd-set-option.c') diff --git a/cmd-set-option.c b/cmd-set-option.c index e04aa7ff..c6f83796 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -30,15 +30,6 @@ static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *); -static int cmd_set_option_set(struct cmd *, struct cmdq_item *, - struct options *, struct options_entry *, const char *); -static int cmd_set_option_flag(struct cmdq_item *, - const struct options_table_entry *, struct options *, - const char *); -static int cmd_set_option_choice(struct cmdq_item *, - const struct options_table_entry *, struct options *, - const char *); - const struct cmd_entry cmd_set_option_entry = { .name = "set-option", .alias = "set", @@ -84,10 +75,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) struct args *args = cmd_get_args(self); int append = args_has(args, 'a'); struct cmd_find_state *target = cmdq_get_target(item); - struct client *loop; - struct session *s = target->s; - struct window *w; - struct window_pane *wp; struct options *oo; struct options_entry *parent, *o; char *name, *argument, *value = NULL, *cause; @@ -138,7 +125,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) parent = options_get(oo, name); /* Check that array options and indexes match up. */ - if (idx != -1 && (*name == '@' || !options_isarray(parent))) { + if (idx != -1 && (*name == '@' || !options_is_array(parent))) { cmdq_error(item, "not an array: %s", argument); goto fail; } @@ -185,10 +172,15 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) goto fail; } options_set_string(oo, name, append, "%s", value); - } else if (idx == -1 && !options_isarray(parent)) { - error = cmd_set_option_set(self, item, oo, parent, value); - if (error != 0) + } else if (idx == -1 && !options_is_array(parent)) { + error = options_from_string(oo, options_table_entry(parent), + options_table_entry(parent)->name, value, + args_has(args, 'a'), &cause); + if (error != 0) { + cmdq_error(item, "%s", cause); + free(cause); goto fail; + } } else { if (value == NULL) { cmdq_error(item, "empty value"); @@ -212,51 +204,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) } } - /* Update timers and so on for various options. */ - if (strcmp(name, "automatic-rename") == 0) { - RB_FOREACH(w, windows, &windows) { - if (w->active == NULL) - continue; - if (options_get_number(w->options, "automatic-rename")) - w->active->flags |= PANE_CHANGED; - } - } - if (strcmp(name, "key-table") == 0) { - TAILQ_FOREACH(loop, &clients, entry) - server_client_set_key_table(loop, NULL); - } - if (strcmp(name, "user-keys") == 0) { - TAILQ_FOREACH(loop, &clients, entry) { - if (loop->tty.flags & TTY_OPENED) - tty_keys_build(&loop->tty); - } - } - if (strcmp(name, "status") == 0 || - strcmp(name, "status-interval") == 0) - status_timer_start_all(); - if (strcmp(name, "monitor-silence") == 0) - alerts_reset_all(); - if (strcmp(name, "window-style") == 0 || - strcmp(name, "window-active-style") == 0) { - RB_FOREACH(wp, window_pane_tree, &all_window_panes) - wp->flags |= PANE_STYLECHANGED; - } - if (strcmp(name, "pane-border-status") == 0) { - RB_FOREACH(w, windows, &windows) - layout_fix_panes(w); - } - RB_FOREACH(s, sessions, &sessions) - status_update_cache(s); - - /* - * Update sizes and redraw. May not always be necessary but do it - * anyway. - */ - recalculate_sizes(); - TAILQ_FOREACH(loop, &clients, entry) { - if (loop->session != NULL) - server_redraw_client(loop); - } + options_push_changes(name); out: free(argument); @@ -270,147 +218,3 @@ fail: free(name); return (CMD_RETURN_ERROR); } - -static int -cmd_set_option_check_string(const struct options_table_entry *oe, - const char *value, char **cause) -{ - struct style sy; - - if (strcmp(oe->name, "default-shell") == 0 && !checkshell(value)) { - xasprintf(cause, "not a suitable shell: %s", value); - return (-1); - } - if (oe->pattern != NULL && fnmatch(oe->pattern, value, 0) != 0) { - xasprintf(cause, "value is invalid: %s", value); - return (-1); - } - if ((oe->flags & OPTIONS_TABLE_IS_STYLE) && - strstr(value, "#{") == NULL && - style_parse(&sy, &grid_default_cell, value) != 0) { - xasprintf(cause, "invalid style: %s", value); - return (-1); - } - return (0); -} - -static int -cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo, - struct options_entry *parent, const char *value) -{ - const struct options_table_entry *oe; - struct args *args = cmd_get_args(self); - int append = args_has(args, 'a'); - long long number; - const char *errstr, *new; - char *old, *cause; - key_code key; - - oe = options_table_entry(parent); - if (value == NULL && - oe->type != OPTIONS_TABLE_FLAG && - oe->type != OPTIONS_TABLE_CHOICE) { - cmdq_error(item, "empty value"); - return (-1); - } - - switch (oe->type) { - case OPTIONS_TABLE_STRING: - old = xstrdup(options_get_string(oo, oe->name)); - options_set_string(oo, oe->name, append, "%s", value); - new = options_get_string(oo, oe->name); - if (cmd_set_option_check_string(oe, new, &cause) != 0) { - cmdq_error(item, "%s", cause); - free(cause); - - options_set_string(oo, oe->name, 0, "%s", old); - free(old); - return (-1); - } - free(old); - return (0); - case OPTIONS_TABLE_NUMBER: - number = strtonum(value, oe->minimum, oe->maximum, &errstr); - if (errstr != NULL) { - cmdq_error(item, "value is %s: %s", errstr, value); - return (-1); - } - options_set_number(oo, oe->name, number); - return (0); - case OPTIONS_TABLE_KEY: - key = key_string_lookup_string(value); - if (key == KEYC_UNKNOWN) { - cmdq_error(item, "bad key: %s", value); - return (-1); - } - options_set_number(oo, oe->name, key); - return (0); - case OPTIONS_TABLE_COLOUR: - if ((number = colour_fromstring(value)) == -1) { - cmdq_error(item, "bad colour: %s", value); - return (-1); - } - options_set_number(oo, oe->name, number); - return (0); - case OPTIONS_TABLE_FLAG: - return (cmd_set_option_flag(item, oe, oo, value)); - case OPTIONS_TABLE_CHOICE: - return (cmd_set_option_choice(item, oe, oo, value)); - case OPTIONS_TABLE_COMMAND: - break; - } - return (-1); -} - -static int -cmd_set_option_flag(struct cmdq_item *item, - const struct options_table_entry *oe, struct options *oo, - const char *value) -{ - int flag; - - if (value == NULL || *value == '\0') - flag = !options_get_number(oo, oe->name); - else if (strcmp(value, "1") == 0 || - strcasecmp(value, "on") == 0 || - strcasecmp(value, "yes") == 0) - flag = 1; - else if (strcmp(value, "0") == 0 || - strcasecmp(value, "off") == 0 || - strcasecmp(value, "no") == 0) - flag = 0; - else { - cmdq_error(item, "bad value: %s", value); - return (-1); - } - options_set_number(oo, oe->name, flag); - return (0); -} - -static int -cmd_set_option_choice(struct cmdq_item *item, - const struct options_table_entry *oe, struct options *oo, - const char *value) -{ - const char **cp; - int n, choice = -1; - - if (value == NULL) { - choice = options_get_number(oo, oe->name); - if (choice < 2) - choice = !choice; - } else { - n = 0; - for (cp = oe->choices; *cp != NULL; cp++) { - if (strcmp(*cp, value) == 0) - choice = n; - n++; - } - if (choice == -1) { - cmdq_error(item, "unknown value: %s", value); - return (-1); - } - } - options_set_number(oo, oe->name, choice); - return (0); -} -- cgit From 574a9e4b6c7a419b60668c30916327aa7e65d2c8 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 16 May 2020 16:50:55 +0000 Subject: Move lazy resize from the pane to the window, there is no point in resizing the window unless it is the current window, and if we do and don't resize the pane until later there are problems if the size changes from A to B then back to A. --- cmd-set-option.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd-set-option.c') diff --git a/cmd-set-option.c b/cmd-set-option.c index c6f83796..36579f29 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -18,7 +18,6 @@ #include -#include #include #include -- cgit