diff options
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 356 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-set-window-option.c | 165 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-show-options.c | 40 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-show-window-options.c | 27 | ||||
-rw-r--r-- | usr.bin/tmux/options-cmd.c | 263 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 26 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 28 |
9 files changed, 410 insertions, 515 deletions
diff --git a/usr.bin/tmux/Makefile b/usr.bin/tmux/Makefile index c8533d8aa04..6c73736cdfe 100644 --- a/usr.bin/tmux/Makefile +++ b/usr.bin/tmux/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.31 2009/12/01 18:42:38 nicm Exp $ +# $OpenBSD: Makefile,v 1.32 2009/12/03 17:44:02 nicm Exp $ PROG= tmux SRCS= attributes.c cfg.c client.c clock.c \ @@ -33,7 +33,7 @@ SRCS= attributes.c cfg.c client.c clock.c \ colour.c environ.c grid-view.c grid-utf8.c grid.c input-keys.c \ imsg.c imsg-buffer.c input.c key-bindings.c key-string.c \ layout-set.c layout.c log.c job.c \ - mode-key.c names.c options-cmd.c options.c paste.c procname.c \ + mode-key.c names.c options.c paste.c procname.c \ resize.c screen-redraw.c screen-write.c screen.c session.c status.c \ server-fn.c server.c server-client.c server-window.c \ tmux.c tty-keys.c tty-term.c tty.c utf8.c \ diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 5f1fad90b1f..f8f69a91eb6 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.26 2009/11/18 13:16:33 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.27 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,10 +29,27 @@ int cmd_set_option_exec(struct cmd *, struct cmd_ctx *); +const char *cmd_set_option_print( + const struct set_option_entry *, struct options_entry *); +void cmd_set_option_string(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *, int); +void cmd_set_option_number(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); +void cmd_set_option_keys(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); +void cmd_set_option_colour(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); +void cmd_set_option_attributes(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); +void cmd_set_option_flag(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); +void cmd_set_option_choice(struct cmd_ctx *, + struct options *, const struct set_option_entry *, char *); + const struct cmd_entry cmd_set_option_entry = { "set-option", "set", - "[-agu] " CMD_TARGET_SESSION_USAGE " option [value]", - CMD_ARG12, "agu", + "[-aguw] [-t target-session|target-window] option [value]", + CMD_ARG12, "aguw", NULL, cmd_target_parse, cmd_set_option_exec, @@ -40,6 +57,12 @@ const struct cmd_entry cmd_set_option_entry = { cmd_target_print }; +const char *set_option_mode_keys_list[] = { + "emacs", "vi", NULL +}; +const char *set_option_clock_mode_style_list[] = { + "12", "24", NULL +}; const char *set_option_status_keys_list[] = { "emacs", "vi", NULL }; @@ -49,7 +72,8 @@ const char *set_option_status_justify_list[] = { const char *set_option_bell_action_list[] = { "none", "any", "current", NULL }; -const struct set_option_entry set_option_table[] = { + +const struct set_option_entry set_session_option_table[] = { { "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list }, { "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, @@ -101,11 +125,45 @@ const struct set_option_entry set_option_table[] = { { NULL, 0, 0, 0, NULL } }; +const struct set_option_entry set_window_option_table[] = { + { "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL }, + { "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL }, + { "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL }, + { "clock-mode-style", + SET_OPTION_CHOICE, 0, 0, set_option_clock_mode_style_list }, + { "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, + { "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, + { "main-pane-height", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, + { "main-pane-width", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, + { "mode-attr", SET_OPTION_ATTRIBUTES, 0, 0, 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 }, + { "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL }, + { "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL }, + { "monitor-content", SET_OPTION_STRING, 0, 0, NULL }, + { "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL }, + { "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL }, + { "utf8", SET_OPTION_FLAG, 0, 0, NULL }, + { "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL }, + { "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "window-status-current-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL }, + { "window-status-current-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "window-status-current-fg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "window-status-current-format", SET_OPTION_STRING, 0, 0, NULL }, + { "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "window-status-format", SET_OPTION_STRING, 0, 0, NULL }, + { "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL } +}; + int cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; + const struct set_option_entry *table; struct session *s; + struct winlink *wl; struct client *c; struct options *oo; const struct set_option_entry *entry, *opt; @@ -114,12 +172,26 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) u_int i; int try_again; - if (cmd_check_flag(data->chflags, 'g')) - oo = &global_s_options; - else { - if ((s = cmd_find_session(ctx, data->target)) == NULL) - return (-1); - oo = &s->options; + if (cmd_check_flag(data->chflags, 'w')) { + table = set_window_option_table; + if (cmd_check_flag(data->chflags, 'g')) + oo = &global_w_options; + else { + wl = cmd_find_window(ctx, data->target, NULL); + if (wl == NULL) + return (-1); + oo = &wl->window->options; + } + } else { + table = set_session_option_table; + if (cmd_check_flag(data->chflags, 'g')) + oo = &global_s_options; + else { + s = cmd_find_session(ctx, data->target); + if (s == NULL) + return (-1); + oo = &s->options; + } } if (*data->arg == '\0') { @@ -128,7 +200,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) } entry = NULL; - for (opt = set_option_table; opt->name != NULL; opt++) { + for (opt = table; opt->name != NULL; opt++) { if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0) continue; if (entry != NULL) { @@ -163,31 +235,36 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) } else { switch (entry->type) { case SET_OPTION_STRING: - set_option_string(ctx, oo, entry, + cmd_set_option_string(ctx, oo, entry, data->arg2, cmd_check_flag(data->chflags, 'a')); break; case SET_OPTION_NUMBER: - set_option_number(ctx, oo, entry, data->arg2); + cmd_set_option_number(ctx, oo, entry, data->arg2); break; case SET_OPTION_KEYS: - set_option_keys(ctx, oo, entry, data->arg2); + cmd_set_option_keys(ctx, oo, entry, data->arg2); break; case SET_OPTION_COLOUR: - set_option_colour(ctx, oo, entry, data->arg2); + cmd_set_option_colour(ctx, oo, entry, data->arg2); break; case SET_OPTION_ATTRIBUTES: - set_option_attributes(ctx, oo, entry, data->arg2); + cmd_set_option_attributes(ctx, oo, entry, data->arg2); break; case SET_OPTION_FLAG: - set_option_flag(ctx, oo, entry, data->arg2); + cmd_set_option_flag(ctx, oo, entry, data->arg2); break; case SET_OPTION_CHOICE: - set_option_choice(ctx, oo, entry, data->arg2); + cmd_set_option_choice(ctx, oo, entry, data->arg2); break; } } recalculate_sizes(); + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL && c->session != NULL) + server_redraw_client(c); + } /* * Special-case: kill all persistent jobs if status-left, status-right @@ -196,7 +273,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) */ if (strcmp(entry->name, "status-left") == 0 || strcmp(entry->name, "status-right") == 0 || - strcmp(entry->name, "set-titles-string") == 0) { + strcmp(entry->name, "set-titles-string") == 0 || + strcmp(entry->name, "window-status-format") == 0) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); if (c == NULL || c->session == NULL) @@ -222,3 +300,243 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); } + +const char * +cmd_set_option_print( + const struct set_option_entry *entry, struct options_entry *o) +{ + static char out[BUFSIZ]; + const char *s; + struct keylist *keylist; + u_int i; + + *out = '\0'; + switch (entry->type) { + case SET_OPTION_STRING: + xsnprintf(out, sizeof out, "\"%s\"", o->str); + break; + case SET_OPTION_NUMBER: + xsnprintf(out, sizeof out, "%lld", o->num); + break; + case SET_OPTION_KEYS: + keylist = o->data; + for (i = 0; i < ARRAY_LENGTH(keylist); i++) { + strlcat(out, key_string_lookup_key( + ARRAY_ITEM(keylist, i)), sizeof out); + if (i != ARRAY_LENGTH(keylist) - 1) + strlcat(out, ",", sizeof out); + } + break; + case SET_OPTION_COLOUR: + s = colour_tostring(o->num); + xsnprintf(out, sizeof out, "%s", s); + break; + case SET_OPTION_ATTRIBUTES: + s = attributes_tostring(o->num); + xsnprintf(out, sizeof out, "%s", s); + break; + case SET_OPTION_FLAG: + if (o->num) + strlcpy(out, "on", sizeof out); + else + strlcpy(out, "off", sizeof out); + break; + case SET_OPTION_CHOICE: + s = entry->choices[o->num]; + xsnprintf(out, sizeof out, "%s", s); + break; + } + return (out); +} + +void +cmd_set_option_string(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value, int append) +{ + struct options_entry *o; + char *oldvalue, *newvalue; + + if (value == NULL) { + ctx->error(ctx, "empty value"); + return; + } + + if (append) { + oldvalue = options_get_string(oo, entry->name); + xasprintf(&newvalue, "%s%s", oldvalue, value); + } else + newvalue = value; + + o = options_set_string(oo, entry->name, "%s", newvalue); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); + + if (newvalue != value) + xfree(newvalue); +} + +void +cmd_set_option_number(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + 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; + } + + o = options_set_number(oo, entry->name, number); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} + +void +cmd_set_option_keys(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + struct keylist *keylist; + char *copyvalue, *ptr, *str; + int key; + + if (value == NULL) { + ctx->error(ctx, "empty value"); + return; + } + + keylist = xmalloc(sizeof *keylist); + ARRAY_INIT(keylist); + + ptr = copyvalue = xstrdup(value); + while ((str = strsep(&ptr, ",")) != NULL) { + if ((key = key_string_lookup_string(str)) == KEYC_NONE) { + xfree(keylist); + ctx->error(ctx, "unknown key: %s", str); + xfree(copyvalue); + return; + } + ARRAY_ADD(keylist, key); + } + xfree(copyvalue); + + o = options_set_data(oo, entry->name, keylist, xfree); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} + +void +cmd_set_option_colour(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + int colour; + + if (value == NULL) { + ctx->error(ctx, "empty value"); + return; + } + + if ((colour = colour_fromstring(value)) == -1) { + ctx->error(ctx, "bad colour: %s", value); + return; + } + + o = options_set_number(oo, entry->name, colour); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} + +void +cmd_set_option_attributes(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + int attr; + + if (value == NULL) { + ctx->error(ctx, "empty value"); + return; + } + + if ((attr = attributes_fromstring(value)) == -1) { + ctx->error(ctx, "bad attributes: %s", value); + return; + } + + o = options_set_number(oo, entry->name, attr); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} + +void +cmd_set_option_flag(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + 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; + } + } + + o = options_set_number(oo, entry->name, flag); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} + +void +cmd_set_option_choice(struct cmd_ctx *ctx, struct options *oo, + const struct set_option_entry *entry, char *value) +{ + struct options_entry *o; + 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 value: %s", value); + return; + } + choice = n - 1; + } + if (choice == -1) { + ctx->error(ctx, "unknown option value: %s", value); + return; + } + + o = options_set_number(oo, entry->name, choice); + ctx->info(ctx, + "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); +} diff --git a/usr.bin/tmux/cmd-set-window-option.c b/usr.bin/tmux/cmd-set-window-option.c index 3826982d2d1..306a8ea988a 100644 --- a/usr.bin/tmux/cmd-set-window-option.c +++ b/usr.bin/tmux/cmd-set-window-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-window-option.c,v 1.15 2009/11/19 16:22:10 nicm Exp $ */ +/* $OpenBSD: cmd-set-window-option.c,v 1.16 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -18,13 +18,10 @@ #include <sys/types.h> -#include <stdlib.h> -#include <string.h> - #include "tmux.h" /* - * Set a window option. + * Set a window option. This is just an alias for set-option -w. */ int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *); @@ -40,165 +37,11 @@ const struct cmd_entry cmd_set_window_option_entry = { cmd_target_print }; -const char *set_option_mode_keys_list[] = { - "emacs", "vi", NULL -}; -const char *set_option_clock_mode_style_list[] = { - "12", "24", NULL -}; -const struct set_option_entry set_window_option_table[] = { - { "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL }, - { "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL }, - { "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL }, - { "clock-mode-style", - SET_OPTION_CHOICE, 0, 0, set_option_clock_mode_style_list }, - { "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, - { "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, - { "main-pane-height", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, - { "main-pane-width", SET_OPTION_NUMBER, 1, INT_MAX, NULL }, - { "mode-attr", SET_OPTION_ATTRIBUTES, 0, 0, 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 }, - { "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL }, - { "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL }, - { "monitor-content", SET_OPTION_STRING, 0, 0, NULL }, - { "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL }, - { "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL }, - { "utf8", SET_OPTION_FLAG, 0, 0, NULL }, - { "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL }, - { "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL }, - { "window-status-current-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL }, - { "window-status-current-bg", SET_OPTION_COLOUR, 0, 0, NULL }, - { "window-status-current-fg", SET_OPTION_COLOUR, 0, 0, NULL }, - { "window-status-current-format", SET_OPTION_STRING, 0, 0, NULL }, - { "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL }, - { "window-status-format", SET_OPTION_STRING, 0, 0, NULL }, - { "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL }, - { NULL, 0, 0, 0, NULL } -}; - int cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; - struct winlink *wl; - struct client *c; - struct options *oo; - const struct set_option_entry *entry, *opt; - struct jobs *jobs; - struct job *job, *nextjob; - u_int i; - int try_again; - - if (cmd_check_flag(data->chflags, 'g')) - oo = &global_w_options; - else { - if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) - return (-1); - oo = &wl->window->options; - } - - if (*data->arg == '\0') { - ctx->error(ctx, "invalid option"); - return (-1); - } - - entry = NULL; - for (opt = set_window_option_table; opt->name != NULL; opt++) { - if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0) - continue; - if (entry != NULL) { - ctx->error(ctx, "ambiguous option: %s", data->arg); - return (-1); - } - entry = opt; - - /* Bail now if an exact match. */ - if (strcmp(entry->name, data->arg) == 0) - break; - } - if (entry == NULL) { - ctx->error(ctx, "unknown option: %s", data->arg); - return (-1); - } - - if (cmd_check_flag(data->chflags, 'u')) { - if (cmd_check_flag(data->chflags, 'g')) { - ctx->error(ctx, - "can't unset global option: %s", entry->name); - return (-1); - } - if (data->arg2 != NULL) { - ctx->error(ctx, - "value passed to unset option: %s", entry->name); - return (-1); - } - - options_remove(oo, entry->name); - ctx->info(ctx, "unset option: %s", entry->name); - } else { - switch (entry->type) { - case SET_OPTION_STRING: - set_option_string(ctx, oo, entry, - data->arg2, cmd_check_flag(data->chflags, 'a')); - break; - case SET_OPTION_NUMBER: - set_option_number(ctx, oo, entry, data->arg2); - break; - case SET_OPTION_KEYS: - set_option_keys(ctx, oo, entry, data->arg2); - break; - case SET_OPTION_COLOUR: - set_option_colour(ctx, oo, entry, data->arg2); - break; - case SET_OPTION_ATTRIBUTES: - set_option_attributes(ctx, oo, entry, data->arg2); - break; - case SET_OPTION_FLAG: - set_option_flag(ctx, oo, entry, data->arg2); - break; - case SET_OPTION_CHOICE: - set_option_choice(ctx, oo, entry, data->arg2); - break; - } - } - - recalculate_sizes(); - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c != NULL && c->session != NULL) - server_redraw_client(c); - } - - /* - * Special-case: kill all persistent jobs if window-status-format has - * changed. Persistent jobs are only used by the status line at the - * moment so this works XXX. - */ - if (strcmp(entry->name, "window-status-format") == 0) { - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c == NULL || c->session == NULL) - continue; - - jobs = &c->status_jobs; - do { - try_again = 0; - job = RB_ROOT(jobs); - while (job != NULL) { - nextjob = RB_NEXT(jobs, jobs, job); - if (job->flags & JOB_PERSIST) { - job_remove(jobs, job); - try_again = 1; - break; - } - job = nextjob; - } - } while (try_again); - server_redraw_client(c); - } - } - return (0); + cmd_set_flag(&data->chflags, 'w'); + return (cmd_set_option_entry.exec(self, ctx)); } diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c index f183a9ae51f..4d6eae0ec3e 100644 --- a/usr.bin/tmux/cmd-show-options.c +++ b/usr.bin/tmux/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-options.c,v 1.7 2009/11/13 19:53:29 nicm Exp $ */ +/* $OpenBSD: cmd-show-options.c,v 1.8 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -31,8 +31,8 @@ int cmd_show_options_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_show_options_entry = { "show-options", "show", - "[-g] " CMD_TARGET_SESSION_USAGE, - 0, "g", + "[-gw] [-t target-session|target-window]", + 0, "gw", cmd_target_init, cmd_target_parse, cmd_show_options_exec, @@ -43,25 +43,41 @@ const struct cmd_entry cmd_show_options_entry = { int cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_target_data *data = self->data; + struct cmd_target_data *data = self->data; + const struct set_option_entry *table; struct session *s; + struct winlink *wl; struct options *oo; struct options_entry *o; const struct set_option_entry *entry; const char *optval; - if (cmd_check_flag(data->chflags, 'g')) - oo = &global_s_options; - else { - if ((s = cmd_find_session(ctx, data->target)) == NULL) - return (-1); - oo = &s->options; + if (cmd_check_flag(data->chflags, 'w')) { + table = set_window_option_table; + if (cmd_check_flag(data->chflags, 'g')) + oo = &global_w_options; + else { + wl = cmd_find_window(ctx, data->target, NULL); + if (wl == NULL) + return (-1); + oo = &wl->window->options; + } + } else { + table = set_session_option_table; + if (cmd_check_flag(data->chflags, 'g')) + oo = &global_s_options; + else { + s = cmd_find_session(ctx, data->target); + if (s == NULL) + return (-1); + oo = &s->options; + } } - for (entry = set_option_table; entry->name != NULL; entry++) { + for (entry = table; entry->name != NULL; entry++) { if ((o = options_find1(oo, entry->name)) == NULL) continue; - optval = set_option_print(entry, o); + optval = cmd_set_option_print(entry, o); ctx->print(ctx, "%s %s", entry->name, optval); } diff --git a/usr.bin/tmux/cmd-show-window-options.c b/usr.bin/tmux/cmd-show-window-options.c index 75eff1a544d..645137912d8 100644 --- a/usr.bin/tmux/cmd-show-window-options.c +++ b/usr.bin/tmux/cmd-show-window-options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-window-options.c,v 1.7 2009/11/13 19:53:29 nicm Exp $ */ +/* $OpenBSD: cmd-show-window-options.c,v 1.8 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -24,7 +24,7 @@ #include "tmux.h" /* - * Show window options. + * Show window options. This is an alias for show-options -w. */ int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *); @@ -44,26 +44,7 @@ int cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; - struct winlink *wl; - struct options *oo; - struct options_entry *o; - const struct set_option_entry *entry; - const char *optval; - if (cmd_check_flag(data->chflags, 'g')) - oo = &global_w_options; - else { - if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) - return (-1); - oo = &wl->window->options; - } - - for (entry = set_window_option_table; entry->name != NULL; entry++) { - if ((o = options_find1(oo, entry->name)) == NULL) - continue; - optval = set_option_print(entry, o); - ctx->print(ctx, "%s %s", entry->name, optval); - } - - return (0); + cmd_set_flag(&data->chflags, 'w'); + return (cmd_show_options_entry.exec(self, ctx)); } diff --git a/usr.bin/tmux/options-cmd.c b/usr.bin/tmux/options-cmd.c deleted file mode 100644 index 7aeae3b63d1..00000000000 --- a/usr.bin/tmux/options-cmd.c +++ /dev/null @@ -1,263 +0,0 @@ -/* $OpenBSD: options-cmd.c,v 1.5 2009/09/22 12:38:10 nicm Exp $ */ - -/* - * 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/types.h> - -#include <stdlib.h> -#include <string.h> - -#include "tmux.h" - -const char * -set_option_print(const struct set_option_entry *entry, struct options_entry *o) -{ - static char out[BUFSIZ]; - const char *s; - struct keylist *keylist; - u_int i; - - *out = '\0'; - switch (entry->type) { - case SET_OPTION_STRING: - xsnprintf(out, sizeof out, "\"%s\"", o->str); - break; - case SET_OPTION_NUMBER: - xsnprintf(out, sizeof out, "%lld", o->num); - break; - case SET_OPTION_KEYS: - keylist = o->data; - for (i = 0; i < ARRAY_LENGTH(keylist); i++) { - strlcat(out, key_string_lookup_key( - ARRAY_ITEM(keylist, i)), sizeof out); - if (i != ARRAY_LENGTH(keylist) - 1) - strlcat(out, ",", sizeof out); - } - break; - case SET_OPTION_COLOUR: - s = colour_tostring(o->num); - xsnprintf(out, sizeof out, "%s", s); - break; - case SET_OPTION_ATTRIBUTES: - s = attributes_tostring(o->num); - xsnprintf(out, sizeof out, "%s", s); - break; - case SET_OPTION_FLAG: - if (o->num) - strlcpy(out, "on", sizeof out); - else - strlcpy(out, "off", sizeof out); - break; - case SET_OPTION_CHOICE: - s = entry->choices[o->num]; - xsnprintf(out, sizeof out, "%s", s); - break; - } - return (out); -} - -void -set_option_string(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value, int append) -{ - struct options_entry *o; - char *oldvalue, *newvalue; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - if (append) { - oldvalue = options_get_string(oo, entry->name); - xasprintf(&newvalue, "%s%s", oldvalue, value); - } else - newvalue = value; - - o = options_set_string(oo, entry->name, "%s", newvalue); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); - - if (newvalue != value) - xfree(newvalue); -} - -void -set_option_number(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - 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; - } - - o = options_set_number(oo, entry->name, number); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} - -void -set_option_keys(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - struct keylist *keylist; - char *copyvalue, *ptr, *str; - int key; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - keylist = xmalloc(sizeof *keylist); - ARRAY_INIT(keylist); - - ptr = copyvalue = xstrdup(value); - while ((str = strsep(&ptr, ",")) != NULL) { - if ((key = key_string_lookup_string(str)) == KEYC_NONE) { - xfree(keylist); - ctx->error(ctx, "unknown key: %s", str); - xfree(copyvalue); - return; - } - ARRAY_ADD(keylist, key); - } - xfree(copyvalue); - - o = options_set_data(oo, entry->name, keylist, xfree); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} - -void -set_option_colour(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - int colour; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - if ((colour = colour_fromstring(value)) == -1) { - ctx->error(ctx, "bad colour: %s", value); - return; - } - - o = options_set_number(oo, entry->name, colour); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} - -void -set_option_attributes(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - int attr; - - if (value == NULL) { - ctx->error(ctx, "empty value"); - return; - } - - if ((attr = attributes_fromstring(value)) == -1) { - ctx->error(ctx, "bad attributes: %s", value); - return; - } - - o = options_set_number(oo, entry->name, attr); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} - -void -set_option_flag(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - 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; - } - } - - o = options_set_number(oo, entry->name, flag); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} - -void -set_option_choice(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) -{ - struct options_entry *o; - 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; - } - - o = options_set_number(oo, entry->name, choice); - ctx->info( - ctx, "set option: %s -> %s", o->name, set_option_print(entry, o)); -} diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 5cfb8d8fbb8..d6c893bdea8 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.53 2009/11/26 22:28:24 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.54 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1115,7 +1115,7 @@ char * status_prompt_complete(const char *s) { const struct cmd_entry **cmdent; - const struct set_option_entry *optent; + const struct set_option_entry *entry; ARRAY_DECL(, const char *) list; char *prefix, *s2; u_int i; @@ -1130,13 +1130,13 @@ status_prompt_complete(const char *s) if (strncmp((*cmdent)->name, s, strlen(s)) == 0) ARRAY_ADD(&list, (*cmdent)->name); } - for (optent = set_option_table; optent->name != NULL; optent++) { - if (strncmp(optent->name, s, strlen(s)) == 0) - ARRAY_ADD(&list, optent->name); + for (entry = set_session_option_table; entry->name != NULL; entry++) { + if (strncmp(entry->name, s, strlen(s)) == 0) + ARRAY_ADD(&list, entry->name); } - for (optent = set_window_option_table; optent->name != NULL; optent++) { - if (strncmp(optent->name, s, strlen(s)) == 0) - ARRAY_ADD(&list, optent->name); + for (entry = set_window_option_table; entry->name != NULL; entry++) { + if (strncmp(entry->name, s, strlen(s)) == 0) + ARRAY_ADD(&list, entry->name); } /* If none, bail now. */ diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 8794aca6d62..520a4534f56 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.128 2009/12/01 18:42:38 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.129 2009/12/03 17:44:02 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 1 2009 $ +.Dd $Mdocdate: December 3 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -1230,8 +1230,8 @@ command. Commands which set options are as follows: .Bl -tag -width Ds .It Xo Ic set-option -.Op Fl agu -.Op Fl t Ar target-session +.Op Fl aguw +.Op Fl t Ar target-session | Ar target-window .Ar option Ar value .Xc .D1 (alias: Ic set ) @@ -1249,6 +1249,13 @@ The flag unsets an option, so a session inherits the option from the global options - it is not possible to unset a global option. .Pp +With +.Fl w , +this command is equivalent to +.Ic set-window-option +with +.Ar target-window . +.Pp Available session options are: .Bl -tag -width Ds .It Ic base-index Ar index @@ -1831,14 +1838,21 @@ as Shift, Alt or Ctrl. The default is off. .El .It Xo Ic show-options -.Op Fl g -.Op Fl t Ar target-session +.Op Fl gw +.Op Fl t Ar target-session | Ar target-window .Xc .D1 (alias: Ic show ) Show the session options for .Ar target session , or the global session options with .Fl g . +.Pp +If +.Fl w +is used, this command is equivalent to +.Ic show-window-options +with +.Ar target-window . .It Xo Ic show-window-options .Op Fl g .Op Fl t Ar target-window diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 669bd1430d3..0bf19bcd3d0 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.190 2009/12/01 18:42:38 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.191 2009/12/03 17:44:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1233,8 +1233,6 @@ struct set_option_entry { const char **choices; }; -extern const struct set_option_entry set_option_table[]; -extern const struct set_option_entry set_window_option_table[]; /* tmux.c */ extern struct options global_s_options; @@ -1377,24 +1375,6 @@ void tty_keys_init(struct tty *); void tty_keys_free(struct tty *); int tty_keys_next(struct tty *); -/* options-cmd.c */ -const char *set_option_print( - const struct set_option_entry *, struct options_entry *); -void set_option_string(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *, int); -void set_option_number(struct cmd_ctx *, - struct options *, const struct set_option_entry *, char *); -void set_option_keys(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_attributes(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 *); - /* paste.c */ void paste_init_stack(struct paste_stack *); void paste_free_stack(struct paste_stack *); @@ -1410,6 +1390,12 @@ int paste_replace(struct paste_stack *, u_int, char *, size_t); extern const char clock_table[14][5][5]; void clock_draw(struct screen_write_ctx *, int, int); +/* cmd-set-option.c */ +extern const struct set_option_entry set_session_option_table[]; +extern const struct set_option_entry set_window_option_table[]; +const char *cmd_set_option_print( + const struct set_option_entry *, struct options_entry *); + /* cmd.c */ int cmd_pack_argv(int, char **, char *, size_t); int cmd_unpack_argv(char *, size_t, int, char ***); |