4 * Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
27 * This file has a tables with all the server, session and window
28 * options. These tables are the master copy of the options with their real
29 * (user-visible) types, range limits and default values. At start these are
30 * copied into the runtime global options trees (which only has number and
31 * string types). These tables are then used to loop up the real type when
32 * the user sets an option or its value needs to be shown.
35 /* Choice option type lists. */
36 const char *options_table_mode_keys_list
[] = {
39 const char *options_table_clock_mode_style_list
[] = {
42 const char *options_table_status_keys_list
[] = {
45 const char *options_table_status_justify_list
[] = {
46 "left", "centre", "right", NULL
48 const char *options_table_bell_action_list
[] = {
49 "none", "any", "current", NULL
53 const struct options_table_entry server_options_table
[] = {
54 { .name
= "buffer-limit",
55 .type
= OPTIONS_TABLE_NUMBER
,
61 { .name
= "escape-time",
62 .type
= OPTIONS_TABLE_NUMBER
,
68 { .name
= "exit-unattached",
69 .type
= OPTIONS_TABLE_FLAG
,
74 .type
= OPTIONS_TABLE_FLAG
,
75 .default_num
= 0 /* overridden in main() */
81 /* Session options. */
82 const struct options_table_entry session_options_table
[] = {
83 { .name
= "base-index",
84 .type
= OPTIONS_TABLE_NUMBER
,
90 { .name
= "bell-action",
91 .type
= OPTIONS_TABLE_CHOICE
,
92 .choices
= options_table_bell_action_list
,
93 .default_num
= BELL_ANY
96 { .name
= "default-command",
97 .type
= OPTIONS_TABLE_STRING
,
101 { .name
= "default-path",
102 .type
= OPTIONS_TABLE_STRING
,
106 { .name
= "default-shell",
107 .type
= OPTIONS_TABLE_STRING
,
108 .default_str
= _PATH_BSHELL
111 { .name
= "default-terminal",
112 .type
= OPTIONS_TABLE_STRING
,
113 .default_str
= "screen"
116 { .name
= "destroy-unattached",
117 .type
= OPTIONS_TABLE_FLAG
,
121 { .name
= "detach-on-destroy",
122 .type
= OPTIONS_TABLE_FLAG
,
126 { .name
= "display-panes-active-colour",
127 .type
= OPTIONS_TABLE_COLOUR
,
131 { .name
= "display-panes-colour",
132 .type
= OPTIONS_TABLE_COLOUR
,
136 { .name
= "display-panes-time",
137 .type
= OPTIONS_TABLE_NUMBER
,
143 { .name
= "display-time",
144 .type
= OPTIONS_TABLE_NUMBER
,
150 { .name
= "history-limit",
151 .type
= OPTIONS_TABLE_NUMBER
,
157 { .name
= "lock-after-time",
158 .type
= OPTIONS_TABLE_NUMBER
,
164 { .name
= "lock-command",
165 .type
= OPTIONS_TABLE_STRING
,
166 .default_str
= "lock -np"
169 { .name
= "lock-server",
170 .type
= OPTIONS_TABLE_FLAG
,
174 { .name
= "message-attr",
175 .type
= OPTIONS_TABLE_ATTRIBUTES
,
179 { .name
= "message-bg",
180 .type
= OPTIONS_TABLE_COLOUR
,
184 { .name
= "message-fg",
185 .type
= OPTIONS_TABLE_COLOUR
,
189 { .name
= "message-limit",
190 .type
= OPTIONS_TABLE_NUMBER
,
196 { .name
= "mouse-select-pane",
197 .type
= OPTIONS_TABLE_FLAG
,
201 { .name
= "pane-active-border-bg",
202 .type
= OPTIONS_TABLE_COLOUR
,
206 { .name
= "pane-active-border-fg",
207 .type
= OPTIONS_TABLE_COLOUR
,
211 { .name
= "pane-border-bg",
212 .type
= OPTIONS_TABLE_COLOUR
,
216 { .name
= "pane-border-fg",
217 .type
= OPTIONS_TABLE_COLOUR
,
222 .type
= OPTIONS_TABLE_KEYS
,
226 { .name
= "repeat-time",
227 .type
= OPTIONS_TABLE_NUMBER
,
233 { .name
= "set-remain-on-exit",
234 .type
= OPTIONS_TABLE_FLAG
,
238 { .name
= "set-titles",
239 .type
= OPTIONS_TABLE_FLAG
,
243 { .name
= "set-titles-string",
244 .type
= OPTIONS_TABLE_STRING
,
245 .default_str
= "#S:#I:#W - \"#T\""
249 .type
= OPTIONS_TABLE_FLAG
,
253 { .name
= "status-attr",
254 .type
= OPTIONS_TABLE_ATTRIBUTES
,
258 { .name
= "status-bg",
259 .type
= OPTIONS_TABLE_COLOUR
,
263 { .name
= "status-fg",
264 .type
= OPTIONS_TABLE_COLOUR
,
268 { .name
= "status-interval",
269 .type
= OPTIONS_TABLE_NUMBER
,
275 { .name
= "status-justify",
276 .type
= OPTIONS_TABLE_CHOICE
,
277 .choices
= options_table_status_justify_list
,
281 { .name
= "status-keys",
282 .type
= OPTIONS_TABLE_CHOICE
,
283 .choices
= options_table_status_keys_list
,
284 .default_num
= MODEKEY_EMACS
287 { .name
= "status-left",
288 .type
= OPTIONS_TABLE_STRING
,
289 .default_str
= "[#S]"
292 { .name
= "status-left-attr",
293 .type
= OPTIONS_TABLE_ATTRIBUTES
,
297 { .name
= "status-left-bg",
298 .type
= OPTIONS_TABLE_COLOUR
,
302 { .name
= "status-left-fg",
303 .type
= OPTIONS_TABLE_COLOUR
,
307 { .name
= "status-left-length",
308 .type
= OPTIONS_TABLE_NUMBER
,
314 { .name
= "status-right",
315 .type
= OPTIONS_TABLE_STRING
,
316 .default_str
= "\"#22T\" %H:%M %d-%b-%y"
319 { .name
= "status-right-attr",
320 .type
= OPTIONS_TABLE_ATTRIBUTES
,
324 { .name
= "status-right-bg",
325 .type
= OPTIONS_TABLE_COLOUR
,
329 { .name
= "status-right-fg",
330 .type
= OPTIONS_TABLE_COLOUR
,
334 { .name
= "status-right-length",
335 .type
= OPTIONS_TABLE_NUMBER
,
341 { .name
= "status-utf8",
342 .type
= OPTIONS_TABLE_FLAG
,
343 .default_num
= 0 /* overridden in main() */
346 { .name
= "terminal-overrides",
347 .type
= OPTIONS_TABLE_STRING
,
348 .default_str
= "*88col*:colors=88,*256col*:colors=256"
351 { .name
= "update-environment",
352 .type
= OPTIONS_TABLE_STRING
,
353 .default_str
= "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
354 "SSH_CONNECTION WINDOWID XAUTHORITY"
358 { .name
= "visual-activity",
359 .type
= OPTIONS_TABLE_FLAG
,
363 { .name
= "visual-bell",
364 .type
= OPTIONS_TABLE_FLAG
,
368 { .name
= "visual-content",
369 .type
= OPTIONS_TABLE_FLAG
,
373 { .name
= "visual-silence",
374 .type
= OPTIONS_TABLE_FLAG
,
381 /* Window options. */
382 const struct options_table_entry window_options_table
[] = {
383 { .name
= "aggressive-resize",
384 .type
= OPTIONS_TABLE_FLAG
,
388 { .name
= "alternate-screen",
389 .type
= OPTIONS_TABLE_FLAG
,
393 { .name
= "automatic-rename",
394 .type
= OPTIONS_TABLE_FLAG
,
398 { .name
= "clock-mode-colour",
399 .type
= OPTIONS_TABLE_COLOUR
,
403 { .name
= "clock-mode-style",
404 .type
= OPTIONS_TABLE_CHOICE
,
405 .choices
= options_table_clock_mode_style_list
,
409 { .name
= "force-height",
410 .type
= OPTIONS_TABLE_NUMBER
,
416 { .name
= "force-width",
417 .type
= OPTIONS_TABLE_NUMBER
,
423 { .name
= "main-pane-height",
424 .type
= OPTIONS_TABLE_NUMBER
,
430 { .name
= "main-pane-width",
431 .type
= OPTIONS_TABLE_NUMBER
,
437 { .name
= "mode-attr",
438 .type
= OPTIONS_TABLE_ATTRIBUTES
,
443 .type
= OPTIONS_TABLE_COLOUR
,
448 .type
= OPTIONS_TABLE_COLOUR
,
452 { .name
= "mode-keys",
453 .type
= OPTIONS_TABLE_CHOICE
,
454 .choices
= options_table_mode_keys_list
,
455 .default_num
= MODEKEY_EMACS
458 { .name
= "mode-mouse",
459 .type
= OPTIONS_TABLE_FLAG
,
463 { .name
= "monitor-activity",
464 .type
= OPTIONS_TABLE_FLAG
,
468 { .name
= "monitor-content",
469 .type
= OPTIONS_TABLE_STRING
,
473 { .name
= "monitor-silence",
474 .type
= OPTIONS_TABLE_NUMBER
,
480 { .name
= "other-pane-height",
481 .type
= OPTIONS_TABLE_NUMBER
,
487 { .name
= "other-pane-width",
488 .type
= OPTIONS_TABLE_NUMBER
,
494 { .name
= "remain-on-exit",
495 .type
= OPTIONS_TABLE_FLAG
,
499 { .name
= "synchronize-panes",
500 .type
= OPTIONS_TABLE_FLAG
,
505 .type
= OPTIONS_TABLE_FLAG
,
506 .default_num
= 0 /* overridden in main() */
509 { .name
= "window-status-alert-attr",
510 .type
= OPTIONS_TABLE_ATTRIBUTES
,
511 .default_num
= GRID_ATTR_REVERSE
514 { .name
= "window-status-alert-bg",
515 .type
= OPTIONS_TABLE_COLOUR
,
519 { .name
= "window-status-alert-fg",
520 .type
= OPTIONS_TABLE_COLOUR
,
524 { .name
= "window-status-attr",
525 .type
= OPTIONS_TABLE_ATTRIBUTES
,
529 { .name
= "window-status-bg",
530 .type
= OPTIONS_TABLE_COLOUR
,
534 { .name
= "window-status-current-attr",
535 .type
= OPTIONS_TABLE_ATTRIBUTES
,
539 { .name
= "window-status-current-bg",
540 .type
= OPTIONS_TABLE_COLOUR
,
544 { .name
= "window-status-current-fg",
545 .type
= OPTIONS_TABLE_COLOUR
,
549 { .name
= "window-status-current-format",
550 .type
= OPTIONS_TABLE_STRING
,
551 .default_str
= "#I:#W#F"
554 { .name
= "window-status-fg",
555 .type
= OPTIONS_TABLE_COLOUR
,
559 { .name
= "window-status-format",
560 .type
= OPTIONS_TABLE_STRING
,
561 .default_str
= "#I:#W#F"
564 { .name
= "word-separators",
565 .type
= OPTIONS_TABLE_STRING
,
566 .default_str
= " -_@"
569 { .name
= "xterm-keys",
570 .type
= OPTIONS_TABLE_FLAG
,
577 /* Populate an options tree from a table. */
579 options_table_populate_tree(
580 const struct options_table_entry
*table
, struct options
*oo
)
582 const struct options_table_entry
*oe
;
584 for (oe
= table
; oe
->name
!= NULL
; oe
++) {
585 if (oe
->default_str
!= NULL
)
586 options_set_string(oo
, oe
->name
, "%s", oe
->default_str
);
588 options_set_number(oo
, oe
->name
, oe
->default_num
);
592 /* Print an option using its type from the table. */
594 options_table_print_entry(
595 const struct options_table_entry
*oe
, struct options_entry
*o
)
597 static char out
[BUFSIZ
];
599 struct keylist
*keylist
;
604 case OPTIONS_TABLE_STRING
:
605 xsnprintf(out
, sizeof out
, "\"%s\"", o
->str
);
607 case OPTIONS_TABLE_NUMBER
:
608 xsnprintf(out
, sizeof out
, "%lld", o
->num
);
610 case OPTIONS_TABLE_KEYS
:
612 for (i
= 0; i
< ARRAY_LENGTH(keylist
); i
++) {
613 s
= key_string_lookup_key(ARRAY_ITEM(keylist
, i
));
614 strlcat(out
, s
, sizeof out
);
615 if (i
!= ARRAY_LENGTH(keylist
) - 1)
616 strlcat(out
, ",", sizeof out
);
619 case OPTIONS_TABLE_COLOUR
:
620 s
= colour_tostring(o
->num
);
621 xsnprintf(out
, sizeof out
, "%s", s
);
623 case OPTIONS_TABLE_ATTRIBUTES
:
624 s
= attributes_tostring(o
->num
);
625 xsnprintf(out
, sizeof out
, "%s", s
);
627 case OPTIONS_TABLE_FLAG
:
629 strlcpy(out
, "on", sizeof out
);
631 strlcpy(out
, "off", sizeof out
);
633 case OPTIONS_TABLE_CHOICE
:
634 s
= oe
->choices
[o
->num
];
635 xsnprintf(out
, sizeof out
, "%s", s
);