[BACK]Return to cmd-set-window-option.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-set-window-option.c, Revision 1.13

1.13    ! nicm        1: /* $OpenBSD: cmd-set-window-option.c,v 1.12 2009/09/22 12:38:10 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <stdlib.h>
                     22: #include <string.h>
                     23:
                     24: #include "tmux.h"
                     25:
                     26: /*
                     27:  * Set a window option.
                     28:  */
                     29:
                     30: int    cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
                     31:
                     32: const struct cmd_entry cmd_set_window_option_entry = {
                     33:        "set-window-option", "setw",
1.11      nicm       34:        "[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]",
                     35:        CMD_ARG12, CMD_CHFLAG('a')|CMD_CHFLAG('g')|CMD_CHFLAG('u'),
1.1       nicm       36:        NULL,
1.11      nicm       37:        cmd_target_parse,
1.1       nicm       38:        cmd_set_window_option_exec,
1.11      nicm       39:        cmd_target_free,
                     40:        cmd_target_print
1.1       nicm       41: };
                     42:
                     43: const char *set_option_mode_keys_list[] = {
                     44:        "emacs", "vi", NULL
                     45: };
                     46: const char *set_option_clock_mode_style_list[] = {
                     47:        "12", "24", NULL
                     48: };
1.6       nicm       49: const struct set_option_entry set_window_option_table[] = {
1.1       nicm       50:        { "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL },
                     51:        { "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL },
                     52:        { "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL },
                     53:        { "clock-mode-style",
                     54:          SET_OPTION_CHOICE, 0, 0, set_option_clock_mode_style_list },
                     55:        { "force-height", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
                     56:        { "force-width", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
1.5       nicm       57:        { "main-pane-height", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
1.1       nicm       58:        { "main-pane-width", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
                     59:        { "mode-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
                     60:        { "mode-bg", SET_OPTION_COLOUR, 0, 0, NULL },
                     61:        { "mode-fg", SET_OPTION_COLOUR, 0, 0, NULL },
                     62:        { "mode-keys", SET_OPTION_CHOICE, 0, 0, set_option_mode_keys_list },
1.9       nicm       63:        { "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL },
1.1       nicm       64:        { "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL },
                     65:        { "monitor-content", SET_OPTION_STRING, 0, 0, NULL },
                     66:        { "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
1.13    ! nicm       67:        { "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL },
1.1       nicm       68:        { "utf8", SET_OPTION_FLAG, 0, 0, NULL },
                     69:        { "window-status-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
                     70:        { "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
1.7       nicm       71:        { "window-status-current-attr", SET_OPTION_ATTRIBUTES, 0, 0, NULL },
                     72:        { "window-status-current-bg", SET_OPTION_COLOUR, 0, 0, NULL },
                     73:        { "window-status-current-fg", SET_OPTION_COLOUR, 0, 0, NULL },
1.1       nicm       74:        { "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
                     75:        { "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
1.6       nicm       76:        { NULL, 0, 0, 0, NULL }
1.1       nicm       77: };
                     78:
                     79: int
                     80: cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
                     81: {
1.11      nicm       82:        struct cmd_target_data          *data = self->data;
1.1       nicm       83:        struct winlink                  *wl;
                     84:        struct client                   *c;
                     85:        struct options                  *oo;
1.6       nicm       86:        const struct set_option_entry   *entry, *opt;
1.1       nicm       87:        u_int                            i;
                     88:
1.4       nicm       89:        if (data->chflags & CMD_CHFLAG('g'))
1.3       nicm       90:                oo = &global_w_options;
1.1       nicm       91:        else {
                     92:                if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
                     93:                        return (-1);
                     94:                oo = &wl->window->options;
                     95:        }
                     96:
1.11      nicm       97:        if (*data->arg == '\0') {
1.1       nicm       98:                ctx->error(ctx, "invalid option");
                     99:                return (-1);
                    100:        }
                    101:
                    102:        entry = NULL;
1.6       nicm      103:        for (opt = set_window_option_table; opt->name != NULL; opt++) {
1.11      nicm      104:                if (strncmp(opt->name, data->arg, strlen(data->arg)) != 0)
1.1       nicm      105:                        continue;
                    106:                if (entry != NULL) {
1.11      nicm      107:                        ctx->error(ctx, "ambiguous option: %s", data->arg);
1.1       nicm      108:                        return (-1);
                    109:                }
1.6       nicm      110:                entry = opt;
1.1       nicm      111:
                    112:                /* Bail now if an exact match. */
1.11      nicm      113:                if (strcmp(entry->name, data->arg) == 0)
1.1       nicm      114:                        break;
                    115:        }
                    116:        if (entry == NULL) {
1.11      nicm      117:                ctx->error(ctx, "unknown option: %s", data->arg);
1.1       nicm      118:                return (-1);
                    119:        }
                    120:
1.4       nicm      121:        if (data->chflags & CMD_CHFLAG('u')) {
                    122:                if (data->chflags & CMD_CHFLAG('g')) {
1.1       nicm      123:                        ctx->error(ctx,
                    124:                            "can't unset global option: %s", entry->name);
                    125:                        return (-1);
                    126:                }
1.11      nicm      127:                if (data->arg2 != NULL) {
1.1       nicm      128:                        ctx->error(ctx,
                    129:                            "value passed to unset option: %s", entry->name);
                    130:                        return (-1);
                    131:                }
                    132:
                    133:                options_remove(oo, entry->name);
                    134:                ctx->info(ctx, "unset option: %s", entry->name);
                    135:        } else {
                    136:                switch (entry->type) {
                    137:                case SET_OPTION_STRING:
1.10      nicm      138:                        set_option_string(ctx, oo, entry,
1.11      nicm      139:                            data->arg2, data->chflags & CMD_CHFLAG('a'));
1.1       nicm      140:                        break;
                    141:                case SET_OPTION_NUMBER:
1.11      nicm      142:                        set_option_number(ctx, oo, entry, data->arg2);
1.1       nicm      143:                        break;
1.12      nicm      144:                case SET_OPTION_KEYS:
                    145:                        set_option_keys(ctx, oo, entry, data->arg2);
1.1       nicm      146:                        break;
                    147:                case SET_OPTION_COLOUR:
1.11      nicm      148:                        set_option_colour(ctx, oo, entry, data->arg2);
1.1       nicm      149:                        break;
                    150:                case SET_OPTION_ATTRIBUTES:
1.11      nicm      151:                        set_option_attributes(ctx, oo, entry, data->arg2);
1.1       nicm      152:                        break;
                    153:                case SET_OPTION_FLAG:
1.11      nicm      154:                        set_option_flag(ctx, oo, entry, data->arg2);
1.1       nicm      155:                        break;
                    156:                case SET_OPTION_CHOICE:
1.11      nicm      157:                        set_option_choice(ctx, oo, entry, data->arg2);
1.1       nicm      158:                        break;
                    159:                }
                    160:        }
                    161:
                    162:        recalculate_sizes();
                    163:        for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
                    164:                c = ARRAY_ITEM(&clients, i);
                    165:                if (c != NULL && c->session != NULL)
                    166:                        server_redraw_client(c);
                    167:        }
                    168:
                    169:        return (0);
                    170: }