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

Annotation of src/usr.bin/tmux/cmd-show-window-options.c, Revision 1.3

1.3     ! nicm        1: /* $OpenBSD: cmd-show-window-options.c,v 1.2 2009/07/07 19:49:19 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:  * Show window options.
                     28:  */
                     29:
                     30: int    cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *);
                     31:
                     32: const struct cmd_entry cmd_show_window_options_entry = {
                     33:        "show-window-options", "showw",
                     34:        "[-g] " CMD_TARGET_WINDOW_USAGE,
1.3     ! nicm       35:        0, CMD_CHFLAG('g'),
1.1       nicm       36:        cmd_target_init,
                     37:        cmd_target_parse,
                     38:        cmd_show_window_options_exec,
                     39:        cmd_target_send,
                     40:        cmd_target_recv,
                     41:        cmd_target_free,
                     42:        cmd_target_print
                     43: };
                     44:
                     45: int
                     46: cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
                     47: {
                     48:        struct cmd_target_data          *data = self->data;
                     49:        struct winlink                  *wl;
                     50:        struct options                  *oo;
                     51:        const struct set_option_entry   *entry;
                     52:        u_int                            i;
                     53:        char                            *vs;
                     54:        long long                        vn;
                     55:
1.3     ! nicm       56:        if (data->chflags & CMD_CHFLAG('g'))
1.2       nicm       57:                oo = &global_w_options;
1.1       nicm       58:        else {
                     59:                if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
                     60:                        return (-1);
                     61:                oo = &wl->window->options;
                     62:        }
                     63:
                     64:        for (i = 0; i < NSETWINDOWOPTION; i++) {
                     65:                entry = &set_window_option_table[i];
                     66:
                     67:                if (options_find1(oo, entry->name) == NULL)
                     68:                        continue;
                     69:
                     70:                switch (entry->type) {
                     71:                case SET_OPTION_STRING:
                     72:                        vs = options_get_string(oo, entry->name);
                     73:                        ctx->print(ctx, "%s \"%s\"", entry->name, vs);
                     74:                        break;
                     75:                case SET_OPTION_NUMBER:
                     76:                        vn = options_get_number(oo, entry->name);
                     77:                        ctx->print(ctx, "%s %lld", entry->name, vn);
                     78:                        break;
                     79:                case SET_OPTION_KEY:
                     80:                        vn = options_get_number(oo, entry->name);
                     81:                        ctx->print(ctx, "%s %s",
                     82:                            entry->name, key_string_lookup_key(vn));
                     83:                        break;
                     84:                case SET_OPTION_COLOUR:
                     85:                        vn = options_get_number(oo, entry->name);
                     86:                        ctx->print(ctx, "%s %s",
                     87:                            entry->name, colour_tostring(vn));
                     88:                        break;
                     89:                case SET_OPTION_ATTRIBUTES:
                     90:                        vn = options_get_number(oo, entry->name);
                     91:                        ctx->print(ctx, "%s %s",
                     92:                            entry->name, attributes_tostring(vn));
                     93:                        break;
                     94:                case SET_OPTION_FLAG:
                     95:                        vn = options_get_number(oo, entry->name);
                     96:                        if (vn)
                     97:                                ctx->print(ctx, "%s on", entry->name);
                     98:                        else
                     99:                                ctx->print(ctx, "%s off", entry->name);
                    100:                        break;
                    101:                case SET_OPTION_CHOICE:
                    102:                        vn = options_get_number(oo, entry->name);
                    103:                        ctx->print(ctx, "%s %s",
                    104:                            entry->name, entry->choices[vn]);
                    105:                        break;
                    106:                }
                    107:        }
                    108:
                    109:        return (0);
                    110: }