diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-12-08 16:19:51 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-12-08 16:19:51 +0000 |
commit | 7a82e86827e3d863a6dc4f1d50985f287d1ff86b (patch) | |
tree | 34bcc703d5d79065c5ef364be2a6ebfbc13cf6d0 | |
parent | f008d303e75c185eebcbb493b4e6d49bb400f694 (diff) |
Make window options work the same was as session options, add mode-fg/mode-bg options, force -g for global on set/show/setw/showw/
-rw-r--r-- | CHANGES | 46 | ||||
-rw-r--r-- | GNUmakefile | 8 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | cmd-generic.c | 161 | ||||
-rw-r--r-- | cmd-set-option.c | 283 | ||||
-rw-r--r-- | cmd-set-window-option.c | 337 | ||||
-rw-r--r-- | cmd-show-options.c | 115 | ||||
-rw-r--r-- | cmd-show-window-options.c | 79 | ||||
-rw-r--r-- | cmd-string.c | 7 | ||||
-rw-r--r-- | examples/n-marriott.conf | 21 | ||||
-rw-r--r-- | input.c | 4 | ||||
-rw-r--r-- | log.c | 5 | ||||
-rw-r--r-- | options-cmd.c | 152 | ||||
-rw-r--r-- | resize.c | 18 | ||||
-rw-r--r-- | screen-redraw.c | 10 | ||||
-rw-r--r-- | screen-write.c | 6 | ||||
-rw-r--r-- | screen.c | 7 | ||||
-rw-r--r-- | server.c | 6 | ||||
-rw-r--r-- | session.c | 7 | ||||
-rw-r--r-- | status.c | 13 | ||||
-rw-r--r-- | tmux.c | 19 | ||||
-rw-r--r-- | tmux.h | 103 | ||||
-rw-r--r-- | window-copy.c | 18 | ||||
-rw-r--r-- | window-more.c | 11 | ||||
-rw-r--r-- | window-scroll.c | 11 | ||||
-rw-r--r-- | window.c | 5 |
27 files changed, 691 insertions, 769 deletions
@@ -1,3 +1,37 @@ +06 December 2008 + +* Bring set/setw/show/showw into line with other commands. This means that by + default they now affect the current window (if any); the new -g flag must be + passed to set the global options. This changes the behaviour of set/show and + WILL BREAK CURRENT CONFIGURATIONS. + + In summary, whether in the configuration file, the command prompt, or a key + binding, use -g to set a global option, use -t to specify a particular window + or session, or omit both to try and use the current window or session. + + This makes set/show a bit of a pain but is the correct behaviour for + setw/showw and is the same as every other command, so we can put up with a + bit of pain for consistency. +* Redo window options. They now work in the same way to session options with a + global options set. showw/setw commands now have similar syntax to show/set + (including the ability to use abbreviations). + + PLEASE NOTE this includes the following configuration-breaking changes: + + - remain-by-default is now GONE, use "setw -g remain-on-exit" to apply the + global window option instead; + - mode-keys is now a window option rather than session - use "setw [-g] + mode-keys" instead of set. + + There are also some additions: + + - message-fg and message-bg session options to control status line message + colours; + - mode-fg and mode-bg window options to set colours in window modes such as + copy mode. + + The options code still a mess and now there is twice as much of it :-(. + 02 December 2008 * Add support for including the window title in status-left or status-right @@ -272,7 +306,7 @@ 07 June 2008 -* Make status-interval actually changable. +* Make status-interval actually changeable. 06 June 2008 @@ -355,7 +389,7 @@ * -s to specify session name now supports fnmatch(3) wildcards; if multiple sessions are found, or if no -s is specified, the most newly created is used. * If no command is specified, assume new-session. As a byproduct, clean up - command default values into seperate init functions. + command default values into separate init functions. * kill-server command. 02 June 2008 @@ -669,7 +703,7 @@ a serious problem when it comes to things like scrolling. This change consolidates all the range checking and limiting together which should make it easier. -* (mxey) Added window remaming, like "tmux rename [-s session] [-i index] name" +* (mxey) Added window renaming, like "tmux rename [-s session] [-i index] name" 27 September 2007 @@ -728,4 +762,8 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.169 2008-12-05 20:04:06 nicm Exp $ +$Id: CHANGES,v 1.170 2008-12-08 16:19:51 nicm Exp $ + + LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr + LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB + LocalWords: dstidx srcname srcidx winlink lsw nabc sabc Exp diff --git a/GNUmakefile b/GNUmakefile index ee69a306..eaf27ff8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,13 +1,13 @@ -# $Id: GNUmakefile,v 1.42 2008-09-26 06:45:25 nicm Exp $ +# $Id: GNUmakefile,v 1.43 2008-12-08 16:19:51 nicm Exp $ .PHONY: clean PROG= tmux -VERSION= 0.5 +VERSION= 0.6 DATE= $(shell date +%Y%m%d-%H%M) -#DEBUG= 1 +DEBUG= 1 META?= \002 @@ -33,7 +33,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-list-commands.c cmd-move-window.c cmd-select-prompt.c \ cmd-respawn-window.c \ window-scroll.c window-more.c window-copy.c options.c paste.c \ - tty.c tty-keys.c tty-write.c colour.c utf8.c + tty.c tty-keys.c tty-write.c colour.c utf8.c options-cmd.c CC?= gcc INCDIRS+= -I. -I- @@ -1,10 +1,10 @@ -# $Id: Makefile,v 1.78 2008-12-05 20:04:06 nicm Exp $ +# $Id: Makefile,v 1.79 2008-12-08 16:19:51 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean update-index.html upload-index.html PROG= tmux -VERSION= 0.5 +VERSION= 0.6 OS!= uname REL!= uname -r @@ -37,7 +37,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-list-commands.c cmd-move-window.c cmd-select-prompt.c \ cmd-respawn-window.c \ window-scroll.c window-more.c window-copy.c options.c paste.c \ - tty.c tty-keys.c tty-write.c colour.c utf8.c + tty.c tty-keys.c tty-write.c colour.c utf8.c options-cmd.c CC?= cc INCDIRS+= -I. -I- -I/usr/local/include @@ -52,3 +52,5 @@ - vi half page scroll - why do home/end work in emacs outside tmux but not inside? - document status line options, title bits +- document mode-fg/mode-bg/message-fg/message-bg +- document window options changes diff --git a/cmd-generic.c b/cmd-generic.c index f1322d1c..c3632055 100644 --- a/cmd-generic.c +++ b/cmd-generic.c @@ -1,4 +1,4 @@ -/* $Id: cmd-generic.c,v 1.13 2008-09-25 23:28:12 nicm Exp $ */ +/* $Id: cmd-generic.c,v 1.14 2008-12-08 16:19:51 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -44,7 +44,7 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_target_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, GETOPT_PREFIX "dkt:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dgkt:")) != EOF) { switch (opt) { case 'd': if (self->entry->flags & CMD_DFLAG) { @@ -52,6 +52,12 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause) break; } goto usage; + case 'g': + if (self->entry->flags & CMD_GFLAG) { + data->flags |= CMD_GFLAG; + break; + } + goto usage; case 'k': if (self->entry->flags & CMD_KFLAG) { data->flags |= CMD_KFLAG; @@ -137,6 +143,8 @@ cmd_target_print(struct cmd *self, char *buf, size_t len) return; if (off < len && data->flags & CMD_DFLAG) off += xsnprintf(buf + off, len - off, " -d"); + if (off < len && data->flags & CMD_GFLAG) + off += xsnprintf(buf + off, len - off, " -g"); if (off < len && data->flags & CMD_KFLAG) off += xsnprintf(buf + off, len - off, " -k"); if (off < len && data->target != NULL) @@ -166,7 +174,7 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_srcdst_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, GETOPT_PREFIX "dks:t:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dgks:t:")) != EOF) { switch (opt) { case 'd': if (self->entry->flags & CMD_DFLAG) { @@ -174,6 +182,12 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause) break; } goto usage; + case 'g': + if (self->entry->flags & CMD_GFLAG) { + data->flags |= CMD_GFLAG; + break; + } + goto usage; case 'k': if (self->entry->flags & CMD_KFLAG) { data->flags |= CMD_KFLAG; @@ -267,6 +281,8 @@ cmd_srcdst_print(struct cmd *self, char *buf, size_t len) return; if (off < len && data->flags & CMD_DFLAG) off += xsnprintf(buf + off, len - off, " -d"); + if (off < len && data->flags & CMD_GFLAG) + off += xsnprintf(buf + off, len - off, " -g"); if (off < len && data->flags & CMD_KFLAG) off += xsnprintf(buf + off, len - off, " -k"); if (off < len && data->src != NULL) @@ -299,7 +315,7 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_buffer_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, GETOPT_PREFIX "b:dkt:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "b:dgkt:")) != EOF) { switch (opt) { case 'b': if (data->buffer == -1) { @@ -318,6 +334,12 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause) break; } goto usage; + case 'g': + if (self->entry->flags & CMD_GFLAG) { + data->flags |= CMD_GFLAG; + break; + } + goto usage; case 'k': if (self->entry->flags & CMD_KFLAG) { data->flags |= CMD_KFLAG; @@ -404,6 +426,8 @@ cmd_buffer_print(struct cmd *self, char *buf, size_t len) return; if (off < len && data->flags & CMD_DFLAG) off += xsnprintf(buf + off, len - off, " -d"); + if (off < len && data->flags & CMD_GFLAG) + off += xsnprintf(buf + off, len - off, " -g"); if (off < len && data->flags & CMD_KFLAG) off += xsnprintf(buf + off, len - off, " -k"); if (off < len && data->buffer != -1) @@ -413,3 +437,132 @@ cmd_buffer_print(struct cmd *self, char *buf, size_t len) if (off < len && data->arg != NULL) off += xsnprintf(buf + off, len - off, " %s", data->arg); } + +void +cmd_option_init(struct cmd *self, unused int key) +{ + struct cmd_option_data *data; + + self->data = data = xmalloc(sizeof *data); + data->flags = 0; + data->target = NULL; + data->option = NULL; + data->value = NULL; +} + +int +cmd_option_parse(struct cmd *self, int argc, char **argv, char **cause) +{ + struct cmd_option_data *data; + int opt; + + /* Don't use the entry version since it may be dependent on key. */ + cmd_option_init(self, 0); + data = self->data; + + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dgkt:")) != EOF) { + switch (opt) { + case 'd': + if (self->entry->flags & CMD_DFLAG) { + data->flags |= CMD_DFLAG; + break; + } + goto usage; + case 'g': + if (self->entry->flags & CMD_GFLAG) { + data->flags |= CMD_GFLAG; + break; + } + goto usage; + case 'k': + if (self->entry->flags & CMD_KFLAG) { + data->flags |= CMD_KFLAG; + break; + } + goto usage; + case 't': + if (data->target == NULL) + data->target = xstrdup(optarg); + break; + default: + goto usage; + } + } + argc -= optind; + argv += optind; + + if (argc == 2) { + data->option = xstrdup(argv[0]); + data->value = xstrdup(argv[1]); + } else if (argc == 1) + data->option = xstrdup(argv[0]); + else + goto usage; + return (0); + +usage: + xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage); + + self->entry->free(self); + return (-1); +} + +void +cmd_option_send(struct cmd *self, struct buffer *b) +{ + struct cmd_option_data *data = self->data; + + buffer_write(b, data, sizeof *data); + cmd_send_string(b, data->target); + cmd_send_string(b, data->option); + cmd_send_string(b, data->value); +} + +void +cmd_option_recv(struct cmd *self, struct buffer *b) +{ + struct cmd_option_data *data; + + self->data = data = xmalloc(sizeof *data); + buffer_read(b, data, sizeof *data); + data->target = cmd_recv_string(b); + data->option = cmd_recv_string(b); + data->value = cmd_recv_string(b); +} + +void +cmd_option_free(struct cmd *self) +{ + struct cmd_option_data *data = self->data; + + if (data->target != NULL) + xfree(data->target); + if (data->option != NULL) + xfree(data->option); + if (data->value != NULL) + xfree(data->value); + xfree(data); +} + +void +cmd_option_print(struct cmd *self, char *buf, size_t len) +{ + struct cmd_option_data *data = self->data; + size_t off = 0; + + off += xsnprintf(buf, len, "%s", self->entry->name); + if (data == NULL) + return; + if (off < len && data->flags & CMD_DFLAG) + off += xsnprintf(buf + off, len - off, " -d"); + if (off < len && data->flags & CMD_GFLAG) + off += xsnprintf(buf + off, len - off, " -g"); + if (off < len && data->flags & CMD_KFLAG) + off += xsnprintf(buf + off, len - off, " -k"); + if (off < len && data->target != NULL) + off += xsnprintf(buf + off, len - off, " -t %s", data->target); + if (off < len && data->option != NULL) + off += xsnprintf(buf + off, len - off, " %s", data->option); + if (off < len && data->value != NULL) + off += xsnprintf(buf + off, len - off, " %s", data->value); +} diff --git a/cmd-set-option.c b/cmd-set-option.c index 93896835..72f6c0a2 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.45 2008-12-05 20:04:06 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.46 2008-12-08 16:19:51 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -28,132 +28,61 @@ * Set an option. */ -int cmd_set_option_parse(struct cmd *, int, char **, char **); void cmd_set_option_exec(struct cmd *, struct cmd_ctx *); -void cmd_set_option_send(struct cmd *, struct buffer *); -void cmd_set_option_recv(struct cmd *, struct buffer *); -void cmd_set_option_free(struct cmd *); -void cmd_set_option_print(struct cmd *, char *, size_t); - -struct cmd_set_option_data { - char *target; - int flag_global; - char *option; - char *value; -}; const struct cmd_entry cmd_set_option_entry = { "set-option", "set", "[-t target-session] option value", - 0, + CMD_GFLAG, NULL, - cmd_set_option_parse, + cmd_option_parse, cmd_set_option_exec, - cmd_set_option_send, - cmd_set_option_recv, - cmd_set_option_free, - cmd_set_option_print + cmd_option_send, + cmd_option_recv, + cmd_option_free, + cmd_option_print }; const char *set_option_bell_action_list[] = { "none", "any", "current", NULL }; -const char *set_option_mode_keys_list[] = { - "emacs", "vi", NULL -}; const struct set_option_entry set_option_table[NSETOPTION] = { { "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list }, { "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, { "default-command", SET_OPTION_STRING, 0, 0, NULL }, { "display-time", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, { "history-limit", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, - { "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list }, + { "message-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "message-fg", SET_OPTION_COLOUR, 0, 0, NULL }, { "prefix", SET_OPTION_KEY, 0, 0, NULL }, - { "remain-by-default", SET_OPTION_FLAG, 0, 0, NULL }, { "set-titles", SET_OPTION_FLAG, 0, 0, NULL }, { "status", SET_OPTION_FLAG, 0, 0, NULL }, { "status-bg", SET_OPTION_COLOUR, 0, 0, NULL }, { "status-fg", SET_OPTION_COLOUR, 0, 0, NULL }, { "status-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "status-left", SET_OPTION_STRING, 0, 0, NULL }, - { "status-right", SET_OPTION_STRING, 0, 0, NULL }, { "status-left-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, + { "status-right", SET_OPTION_STRING, 0, 0, NULL }, { "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, - { "utf8", SET_OPTION_FLAG, 0, 0, NULL }, }; -void set_option_string(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_number(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_key(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_colour(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_flag(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_choice(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); - -int -cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause) -{ - struct cmd_set_option_data *data; - int opt; - - self->data = data = xmalloc(sizeof *data); - data->target = NULL; - data->flag_global = 1; - data->option = NULL; - data->value = NULL; - - while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:s:")) != EOF) { - switch (opt) { - case 't': - if (data->target == NULL) - data->target = xstrdup(optarg); - data->flag_global = 0; - break; - default: - goto usage; - } - } - argc -= optind; - argv += optind; - if (argc != 1 && argc != 2) - goto usage; - - data->option = xstrdup(argv[0]); - if (argc == 2) - data->value = xstrdup(argv[1]); - - return (0); - -usage: - xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage); - - self->entry->free(self); - return (-1); -} - void cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_set_option_data *data = self->data; + struct cmd_option_data *data = self->data; struct session *s; struct client *c; struct options *oo; const struct set_option_entry *entry; u_int i; - if (data == NULL) - return; - - if (data->flag_global || - ((s = cmd_find_session(ctx, data->target))) == NULL) + if (data->flags & CMD_GFLAG) oo = &global_options; - else + else { + if ((s = cmd_find_session(ctx, data->target)) == NULL) + return; oo = &s->options; + } if (*data->option == '\0') { ctx->error(ctx, "invalid option"); @@ -211,183 +140,3 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) if (ctx->cmdclient != NULL) server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } - -void -set_option_string(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - options_set_string(oo, entry->name, "%s", value); -} - -void -set_option_number(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - long long number; - const char *errstr; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - number = strtonum(value, entry->minimum, entry->maximum, &errstr); - if (errstr != NULL) { - ctx->error(ctx, "value is %s: %s", errstr, value); - return; - } - options_set_number(oo, entry->name, number); -} - -void -set_option_key(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - int key; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - if ((key = key_string_lookup_string(value)) == KEYC_NONE) { - ctx->error(ctx, "unknown key: %s", value); - return; - } - options_set_number(oo, entry->name, key); - -} - -void -set_option_colour(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - u_char colour; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - if ((colour = colour_fromstring(value)) > 8) { - ctx->error(ctx, "bad colour: %s", value); - return; - } - - options_set_number(oo, entry->name, colour); -} - -void -set_option_flag(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - int flag; - - if (value == NULL || *value == '\0') - flag = !options_get_number(oo, entry->name); - else { - if ((value[0] == '1' && value[1] == '\0') || - strcasecmp(value, "on") == 0 || - strcasecmp(value, "yes") == 0) - flag = 1; - else if ((value[0] == '0' && value[1] == '\0') || - strcasecmp(value, "off") == 0 || - strcasecmp(value, "no") == 0) - flag = 0; - else { - ctx->error(ctx, "bad value: %s", value); - return; - } - } - - options_set_number(oo, entry->name, flag); -} - -void -set_option_choice(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - const char **choicep; - int n, choice = -1; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - n = 0; - for (choicep = entry->choices; *choicep != NULL; choicep++) { - n++; - if (strncmp(*choicep, value, strlen(value)) != 0) - continue; - - if (choice != -1) { - ctx->error(ctx, "ambiguous option: %s", value); - return; - } - choice = n - 1; - } - if (choice == -1) { - ctx->error(ctx, "unknown option: %s", value); - return; - } - - options_set_number(oo, entry->name, choice); -} - -void -cmd_set_option_send(struct cmd *self, struct buffer *b) -{ - struct cmd_set_option_data *data = self->data; - - buffer_write(b, data, sizeof *data); - cmd_send_string(b, data->target); - cmd_send_string(b, data->option); - cmd_send_string(b, data->value); -} - -void -cmd_set_option_recv(struct cmd *self, struct buffer *b) -{ - struct cmd_set_option_data *data; - - self->data = data = xmalloc(sizeof *data); - buffer_read(b, data, sizeof *data); - data->target = cmd_recv_string(b); - data->option = cmd_recv_string(b); - data->value = cmd_recv_string(b); -} - -void -cmd_set_option_free(struct cmd *self) -{ - struct cmd_set_option_data *data = self->data; - - if (data->target != NULL) - xfree(data->target); - if (data->option != NULL) - xfree(data->option); - if (data->value != NULL) - xfree(data->value); - xfree(data); -} - -void -cmd_set_option_print(struct cmd *self, char *buf, size_t len) -{ - struct cmd_set_option_data *data = self->data; - size_t off = 0; - - off += xsnprintf(buf, len, "%s", self->entry->name); - if (data == NULL) - return; - if (off < len && data->option != NULL) - off += xsnprintf(buf + off, len - off, " %s", data->option); - if (off < len && data->value != NULL) - off += xsnprintf(buf + off, len - off, " %s", data->value); -} diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c index cafce6bb..c628da8d 100644 --- a/cmd-set-window-option.c +++ b/cmd-set-window-option.c @@ -1,7 +1,7 @@ -/* $Id: cmd-set-window-option.c,v 1.13 2008-11-16 13:28:59 nicm Exp $ */ +/* $Id: cmd-set-window-option.c,v 1.14 2008-12-08 16:19:51 nicm Exp $ */ /* - * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> + * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -35,286 +35,105 @@ void cmd_set_window_option_recv(struct cmd *, struct buffer *); void cmd_set_window_option_free(struct cmd *); void cmd_set_window_option_print(struct cmd *, char *, size_t); -struct cmd_set_window_option_data { - char *target; - char *option; - char *value; -}; - const struct cmd_entry cmd_set_window_option_entry = { "set-window-option", "setw", - "[-t target-window] option value", - 0, + "[-g] [-t target-window] option value", + CMD_GFLAG, NULL, - cmd_set_window_option_parse, + cmd_option_parse, cmd_set_window_option_exec, - cmd_set_window_option_send, - cmd_set_window_option_recv, - cmd_set_window_option_free, - cmd_set_window_option_print + cmd_option_send, + cmd_option_recv, + cmd_option_free, + cmd_option_print }; -int -cmd_set_window_option_parse( - struct cmd *self, int argc, char **argv, char **cause) -{ - struct cmd_set_window_option_data *data; - int opt; - - self->data = data = xmalloc(sizeof *data); - data->target = NULL; - data->option = NULL; - data->value = NULL; - - while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:")) != EOF) { - switch (opt) { - case 't': - if (data->target == NULL) - data->target = xstrdup(optarg); - break; - default: - goto usage; - } - } - argc -= optind; - argv += optind; - if (argc != 1 && argc != 2) - goto usage; - - data->option = xstrdup(argv[0]); - if (argc == 2) - data->value = xstrdup(argv[1]); - - return (0); - -usage: - xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage); - - self->entry->free(self); - return (-1); -} +const char *set_option_mode_keys_list[] = { + "emacs", "vi", NULL +}; +const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = { + { "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL }, + { "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, + { "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, + { "mode-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "mode-fg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list }, + { "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL }, + { "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL }, + { "utf8", SET_OPTION_FLAG, 0, 0, NULL }, +}; void cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_set_window_option_data *data = self->data; - struct winlink *wl; - struct session *s; - const char *errstr; - int number, flag; - u_int i; - - if (data == NULL) - return; - - wl = cmd_find_window(ctx, data->target, &s); - if (wl == NULL) - return; + struct cmd_option_data *data = self->data; + struct winlink *wl; + struct client *c; + struct options *oo; + const struct set_option_entry *entry; + u_int i; + + if (data->flags & CMD_GFLAG) + oo = &global_window_options; + else { + if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) + return; + oo = &wl->window->options; + } if (*data->option == '\0') { ctx->error(ctx, "invalid option"); return; } - number = -1; - if (data->value != NULL) { - number = strtonum(data->value, 0, INT_MAX, &errstr); - - flag = -1; - if (number == 1 || strcasecmp(data->value, "on") == 0 || - strcasecmp(data->value, "yes") == 0) - flag = 1; - else if (number == 0 || strcasecmp(data->value, "off") == 0 || - strcasecmp(data->value, "no") == 0) - flag = 0; - } else - flag = -2; - - if (strcmp(data->option, "monitor-activity") == 0) { - if (flag == -1) { - ctx->error(ctx, "bad value: %s", data->value); + entry = NULL; + for (i = 0; i < NSETWINDOWOPTION; i++) { + if (strncmp(set_window_option_table[i].name, + data->option, strlen(data->option)) != 0) + continue; + if (entry != NULL) { + ctx->error(ctx, "ambiguous option: %s", data->option); return; } + entry = &set_window_option_table[i]; - if (flag == -2) - wl->window->flags ^= WINDOW_MONITOR; - else { - if (flag) - wl->window->flags |= WINDOW_MONITOR; - else - wl->window->flags &= ~WINDOW_MONITOR; - } - - if (wl->window->flags & WINDOW_MONITOR) { - ctx->info(ctx, "window %s:%d: set %s", - s->name, wl->idx, data->option); - } else { - ctx->info(ctx, "window %s:%d: cleared %s", - s->name, wl->idx, data->option); - } - - for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { - s = ARRAY_ITEM(&sessions, i); - if (s != NULL) - session_alert_cancel(s, wl); - } - } else if (strcmp(data->option, "aggressive-resize") == 0) { - if (flag == -1) { - ctx->error(ctx, "bad value: %s", data->value); - return; - } - - if (flag == -2) - wl->window->flags ^= WINDOW_AGGRESSIVE; - else { - if (flag) - wl->window->flags |= WINDOW_AGGRESSIVE; - else - wl->window->flags &= ~WINDOW_AGGRESSIVE; - } - - if (wl->window->flags & WINDOW_AGGRESSIVE) { - ctx->info(ctx, "window %s:%d: set %s", - s->name, wl->idx, data->option); - } else { |