Annotation of src/usr.bin/tmux/cmd-show-window-options.c, Revision 1.4
1.4 ! nicm 1: /* $OpenBSD: cmd-show-window-options.c,v 1.3 2009/07/13 23:11:35 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: char *vs;
53: long long vn;
54:
1.3 nicm 55: if (data->chflags & CMD_CHFLAG('g'))
1.2 nicm 56: oo = &global_w_options;
1.1 nicm 57: else {
58: if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
59: return (-1);
60: oo = &wl->window->options;
61: }
62:
1.4 ! nicm 63: for (entry = set_window_option_table; entry->name != NULL; entry++) {
1.1 nicm 64: if (options_find1(oo, entry->name) == NULL)
65: continue;
66:
67: switch (entry->type) {
68: case SET_OPTION_STRING:
69: vs = options_get_string(oo, entry->name);
70: ctx->print(ctx, "%s \"%s\"", entry->name, vs);
71: break;
72: case SET_OPTION_NUMBER:
73: vn = options_get_number(oo, entry->name);
74: ctx->print(ctx, "%s %lld", entry->name, vn);
75: break;
76: case SET_OPTION_KEY:
77: vn = options_get_number(oo, entry->name);
78: ctx->print(ctx, "%s %s",
79: entry->name, key_string_lookup_key(vn));
80: break;
81: case SET_OPTION_COLOUR:
82: vn = options_get_number(oo, entry->name);
83: ctx->print(ctx, "%s %s",
84: entry->name, colour_tostring(vn));
85: break;
86: case SET_OPTION_ATTRIBUTES:
87: vn = options_get_number(oo, entry->name);
88: ctx->print(ctx, "%s %s",
89: entry->name, attributes_tostring(vn));
90: break;
91: case SET_OPTION_FLAG:
92: vn = options_get_number(oo, entry->name);
93: if (vn)
94: ctx->print(ctx, "%s on", entry->name);
95: else
96: ctx->print(ctx, "%s off", entry->name);
97: break;
98: case SET_OPTION_CHOICE:
99: vn = options_get_number(oo, entry->name);
100: ctx->print(ctx, "%s %s",
101: entry->name, entry->choices[vn]);
102: break;
103: }
104: }
105:
106: return (0);
107: }