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_mode_mouse_list
[] = {
40 "off", "on", "copy-mode", NULL
42 const char *options_table_clock_mode_style_list
[] = {
45 const char *options_table_status_keys_list
[] = {
48 const char *options_table_status_justify_list
[] = {
49 "left", "centre", "right", NULL
51 const char *options_table_status_position_list
[] = {
54 const char *options_table_bell_action_list
[] = {
55 "none", "any", "current", NULL
59 const struct options_table_entry server_options_table
[] = {
60 { .name
= "buffer-limit",
61 .type
= OPTIONS_TABLE_NUMBER
,
67 { .name
= "escape-time",
68 .type
= OPTIONS_TABLE_NUMBER
,
74 { .name
= "exit-unattached",
75 .type
= OPTIONS_TABLE_FLAG
,
80 .type
= OPTIONS_TABLE_FLAG
,
81 .default_num
= 0 /* overridden in main() */
84 { .name
= "set-clipboard",
85 .type
= OPTIONS_TABLE_FLAG
,
92 /* Session options. */
93 const struct options_table_entry session_options_table
[] = {
94 { .name
= "assume-paste-time",
95 .type
= OPTIONS_TABLE_NUMBER
,
101 { .name
= "base-index",
102 .type
= OPTIONS_TABLE_NUMBER
,
108 { .name
= "bell-action",
109 .type
= OPTIONS_TABLE_CHOICE
,
110 .choices
= options_table_bell_action_list
,
111 .default_num
= BELL_ANY
114 { .name
= "bell-on-alert",
115 .type
= OPTIONS_TABLE_FLAG
,
119 { .name
= "default-command",
120 .type
= OPTIONS_TABLE_STRING
,
124 { .name
= "default-path",
125 .type
= OPTIONS_TABLE_STRING
,
129 { .name
= "default-shell",
130 .type
= OPTIONS_TABLE_STRING
,
131 .default_str
= _PATH_BSHELL
134 { .name
= "default-terminal",
135 .type
= OPTIONS_TABLE_STRING
,
136 .default_str
= "screen"
139 { .name
= "destroy-unattached",
140 .type
= OPTIONS_TABLE_FLAG
,
144 { .name
= "detach-on-destroy",
145 .type
= OPTIONS_TABLE_FLAG
,
149 { .name
= "display-panes-active-colour",
150 .type
= OPTIONS_TABLE_COLOUR
,
154 { .name
= "display-panes-colour",
155 .type
= OPTIONS_TABLE_COLOUR
,
159 { .name
= "display-panes-time",
160 .type
= OPTIONS_TABLE_NUMBER
,
166 { .name
= "display-time",
167 .type
= OPTIONS_TABLE_NUMBER
,
173 { .name
= "history-limit",
174 .type
= OPTIONS_TABLE_NUMBER
,
180 { .name
= "lock-after-time",
181 .type
= OPTIONS_TABLE_NUMBER
,
187 { .name
= "lock-command",
188 .type
= OPTIONS_TABLE_STRING
,
189 .default_str
= "lock -np"
192 { .name
= "lock-server",
193 .type
= OPTIONS_TABLE_FLAG
,
197 { .name
= "message-attr",
198 .type
= OPTIONS_TABLE_ATTRIBUTES
,
202 { .name
= "message-bg",
203 .type
= OPTIONS_TABLE_COLOUR
,
207 { .name
= "message-command-attr",
208 .type
= OPTIONS_TABLE_ATTRIBUTES
,
212 { .name
= "message-command-bg",
213 .type
= OPTIONS_TABLE_COLOUR
,
217 { .name
= "message-command-fg",
218 .type
= OPTIONS_TABLE_COLOUR
,
222 { .name
= "message-fg",
223 .type
= OPTIONS_TABLE_COLOUR
,
227 { .name
= "message-limit",
228 .type
= OPTIONS_TABLE_NUMBER
,
234 { .name
= "mouse-resize-pane",
235 .type
= OPTIONS_TABLE_FLAG
,
239 { .name
= "mouse-select-pane",
240 .type
= OPTIONS_TABLE_FLAG
,
244 { .name
= "mouse-select-window",
245 .type
= OPTIONS_TABLE_FLAG
,
249 { .name
= "mouse-utf8",
250 .type
= OPTIONS_TABLE_FLAG
,
254 { .name
= "pane-active-border-bg",
255 .type
= OPTIONS_TABLE_COLOUR
,
259 { .name
= "pane-active-border-fg",
260 .type
= OPTIONS_TABLE_COLOUR
,
264 { .name
= "pane-border-bg",
265 .type
= OPTIONS_TABLE_COLOUR
,
269 { .name
= "pane-border-fg",
270 .type
= OPTIONS_TABLE_COLOUR
,
275 .type
= OPTIONS_TABLE_KEY
,
276 .default_num
= '\002',
280 .type
= OPTIONS_TABLE_KEY
,
281 .default_num
= KEYC_NONE
,
284 { .name
= "renumber-windows",
285 .type
= OPTIONS_TABLE_FLAG
,
289 { .name
= "repeat-time",
290 .type
= OPTIONS_TABLE_NUMBER
,
296 { .name
= "set-remain-on-exit",
297 .type
= OPTIONS_TABLE_FLAG
,
301 { .name
= "set-titles",
302 .type
= OPTIONS_TABLE_FLAG
,
306 { .name
= "set-titles-string",
307 .type
= OPTIONS_TABLE_STRING
,
308 .default_str
= "#S:#I:#W - \"#T\""
312 .type
= OPTIONS_TABLE_FLAG
,
316 { .name
= "status-attr",
317 .type
= OPTIONS_TABLE_ATTRIBUTES
,
321 { .name
= "status-bg",
322 .type
= OPTIONS_TABLE_COLOUR
,
326 { .name
= "status-fg",
327 .type
= OPTIONS_TABLE_COLOUR
,
331 { .name
= "status-interval",
332 .type
= OPTIONS_TABLE_NUMBER
,
338 { .name
= "status-justify",
339 .type
= OPTIONS_TABLE_CHOICE
,
340 .choices
= options_table_status_justify_list
,
344 { .name
= "status-keys",
345 .type
= OPTIONS_TABLE_CHOICE
,
346 .choices
= options_table_status_keys_list
,
347 .default_num
= MODEKEY_EMACS
350 { .name
= "status-left",
351 .type
= OPTIONS_TABLE_STRING
,
352 .default_str
= "[#S]"
355 { .name
= "status-left-attr",
356 .type
= OPTIONS_TABLE_ATTRIBUTES
,
360 { .name
= "status-left-bg",
361 .type
= OPTIONS_TABLE_COLOUR
,
365 { .name
= "status-left-fg",
366 .type
= OPTIONS_TABLE_COLOUR
,
370 { .name
= "status-left-length",
371 .type
= OPTIONS_TABLE_NUMBER
,
377 { .name
= "status-position",
378 .type
= OPTIONS_TABLE_CHOICE
,
379 .choices
= options_table_status_position_list
,
383 { .name
= "status-right",
384 .type
= OPTIONS_TABLE_STRING
,
385 .default_str
= "\"#22T\" %H:%M %d-%b-%y"
388 { .name
= "status-right-attr",
389 .type
= OPTIONS_TABLE_ATTRIBUTES
,
393 { .name
= "status-right-bg",
394 .type
= OPTIONS_TABLE_COLOUR
,
398 { .name
= "status-right-fg",
399 .type
= OPTIONS_TABLE_COLOUR
,
403 { .name
= "status-right-length",
404 .type
= OPTIONS_TABLE_NUMBER
,
410 { .name
= "status-utf8",
411 .type
= OPTIONS_TABLE_FLAG
,
412 .default_num
= 0 /* overridden in main() */
415 { .name
= "terminal-overrides",
416 .type
= OPTIONS_TABLE_STRING
,
417 .default_str
= "*88col*:colors=88,*256col*:colors=256"
418 ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
419 ":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
420 ":Cs=\\E[%p1%d q:Csr=\\E[2 q,screen*:XT"
423 { .name
= "update-environment",
424 .type
= OPTIONS_TABLE_STRING
,
425 .default_str
= "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
426 "SSH_CONNECTION WINDOWID XAUTHORITY"
430 { .name
= "visual-activity",
431 .type
= OPTIONS_TABLE_FLAG
,
435 { .name
= "visual-bell",
436 .type
= OPTIONS_TABLE_FLAG
,
440 { .name
= "visual-content",
441 .type
= OPTIONS_TABLE_FLAG
,
445 { .name
= "visual-silence",
446 .type
= OPTIONS_TABLE_FLAG
,
450 { .name
= "word-separators",
451 .type
= OPTIONS_TABLE_STRING
,
452 .default_str
= " -_@"
458 /* Window options. */
459 const struct options_table_entry window_options_table
[] = {
460 { .name
= "aggressive-resize",
461 .type
= OPTIONS_TABLE_FLAG
,
465 { .name
= "allow-rename",
466 .type
= OPTIONS_TABLE_FLAG
,
470 { .name
= "alternate-screen",
471 .type
= OPTIONS_TABLE_FLAG
,
475 { .name
= "automatic-rename",
476 .type
= OPTIONS_TABLE_FLAG
,
480 { .name
= "c0-change-trigger",
481 .type
= OPTIONS_TABLE_NUMBER
,
487 { .name
= "c0-change-interval",
488 .type
= OPTIONS_TABLE_NUMBER
,
494 { .name
= "clock-mode-colour",
495 .type
= OPTIONS_TABLE_COLOUR
,
499 { .name
= "clock-mode-style",
500 .type
= OPTIONS_TABLE_CHOICE
,
501 .choices
= options_table_clock_mode_style_list
,
505 { .name
= "command-prefix",
506 .type
= OPTIONS_TABLE_STRING
,
507 .default_str
= "exec "
510 { .name
= "force-height",
511 .type
= OPTIONS_TABLE_NUMBER
,
517 { .name
= "force-width",
518 .type
= OPTIONS_TABLE_NUMBER
,
524 { .name
= "main-pane-height",
525 .type
= OPTIONS_TABLE_NUMBER
,
531 { .name
= "main-pane-width",
532 .type
= OPTIONS_TABLE_NUMBER
,
538 { .name
= "mode-attr",
539 .type
= OPTIONS_TABLE_ATTRIBUTES
,
544 .type
= OPTIONS_TABLE_COLOUR
,
549 .type
= OPTIONS_TABLE_COLOUR
,
553 { .name
= "mode-keys",
554 .type
= OPTIONS_TABLE_CHOICE
,
555 .choices
= options_table_mode_keys_list
,
556 .default_num
= MODEKEY_EMACS
559 { .name
= "mode-mouse",
560 .type
= OPTIONS_TABLE_CHOICE
,
561 .choices
= options_table_mode_mouse_list
,
565 { .name
= "monitor-activity",
566 .type
= OPTIONS_TABLE_FLAG
,
570 { .name
= "monitor-content",
571 .type
= OPTIONS_TABLE_STRING
,
575 { .name
= "monitor-silence",
576 .type
= OPTIONS_TABLE_NUMBER
,
582 { .name
= "other-pane-height",
583 .type
= OPTIONS_TABLE_NUMBER
,
589 { .name
= "other-pane-width",
590 .type
= OPTIONS_TABLE_NUMBER
,
596 { .name
= "pane-base-index",
597 .type
= OPTIONS_TABLE_NUMBER
,
599 .maximum
= USHRT_MAX
,
603 { .name
= "remain-on-exit",
604 .type
= OPTIONS_TABLE_FLAG
,
608 { .name
= "synchronize-panes",
609 .type
= OPTIONS_TABLE_FLAG
,
614 .type
= OPTIONS_TABLE_FLAG
,
615 .default_num
= 0 /* overridden in main() */
618 { .name
= "window-status-activity-attr",
619 .type
= OPTIONS_TABLE_ATTRIBUTES
,
620 .default_num
= GRID_ATTR_REVERSE
623 { .name
= "window-status-activity-bg",
624 .type
= OPTIONS_TABLE_COLOUR
,
628 { .name
= "window-status-activity-fg",
629 .type
= OPTIONS_TABLE_COLOUR
,
633 { .name
= "window-status-bell-attr",
634 .type
= OPTIONS_TABLE_ATTRIBUTES
,
635 .default_num
= GRID_ATTR_REVERSE
638 { .name
= "window-status-bell-bg",
639 .type
= OPTIONS_TABLE_COLOUR
,
643 { .name
= "window-status-bell-fg",
644 .type
= OPTIONS_TABLE_COLOUR
,
648 { .name
= "window-status-content-attr",
649 .type
= OPTIONS_TABLE_ATTRIBUTES
,
650 .default_num
= GRID_ATTR_REVERSE
653 { .name
= "window-status-content-bg",
654 .type
= OPTIONS_TABLE_COLOUR
,
658 { .name
= "window-status-content-fg",
659 .type
= OPTIONS_TABLE_COLOUR
,
663 { .name
= "window-status-attr",
664 .type
= OPTIONS_TABLE_ATTRIBUTES
,
668 { .name
= "window-status-bg",
669 .type
= OPTIONS_TABLE_COLOUR
,
673 { .name
= "window-status-current-attr",
674 .type
= OPTIONS_TABLE_ATTRIBUTES
,
678 { .name
= "window-status-current-bg",
679 .type
= OPTIONS_TABLE_COLOUR
,
683 { .name
= "window-status-current-fg",
684 .type
= OPTIONS_TABLE_COLOUR
,
688 { .name
= "window-status-current-format",
689 .type
= OPTIONS_TABLE_STRING
,
690 .default_str
= "#I:#W#F"
693 { .name
= "window-status-last-attr",
694 .type
= OPTIONS_TABLE_ATTRIBUTES
,
698 { .name
= "window-status-last-bg",
699 .type
= OPTIONS_TABLE_COLOUR
,
703 { .name
= "window-status-last-fg",
704 .type
= OPTIONS_TABLE_COLOUR
,
708 { .name
= "window-status-fg",
709 .type
= OPTIONS_TABLE_COLOUR
,
713 { .name
= "window-status-format",
714 .type
= OPTIONS_TABLE_STRING
,
715 .default_str
= "#I:#W#F"
718 { .name
= "window-status-separator",
719 .type
= OPTIONS_TABLE_STRING
,
723 { .name
= "wrap-search",
724 .type
= OPTIONS_TABLE_FLAG
,
728 { .name
= "xterm-keys",
729 .type
= OPTIONS_TABLE_FLAG
,
736 /* Populate an options tree from a table. */
738 options_table_populate_tree(
739 const struct options_table_entry
*table
, struct options
*oo
)
741 const struct options_table_entry
*oe
;
743 for (oe
= table
; oe
->name
!= NULL
; oe
++) {
744 if (oe
->default_str
!= NULL
)
745 options_set_string(oo
, oe
->name
, "%s", oe
->default_str
);
747 options_set_number(oo
, oe
->name
, oe
->default_num
);
751 /* Print an option using its type from the table. */
753 options_table_print_entry(const struct options_table_entry
*oe
,
754 struct options_entry
*o
, int no_quotes
)
756 static char out
[BUFSIZ
];
761 case OPTIONS_TABLE_STRING
:
763 xsnprintf(out
, sizeof out
, "%s", o
->str
);
765 xsnprintf(out
, sizeof out
, "\"%s\"", o
->str
);
767 case OPTIONS_TABLE_NUMBER
:
768 xsnprintf(out
, sizeof out
, "%lld", o
->num
);
770 case OPTIONS_TABLE_KEY
:
771 xsnprintf(out
, sizeof out
, "%s",
772 key_string_lookup_key(o
->num
));
774 case OPTIONS_TABLE_COLOUR
:
775 s
= colour_tostring(o
->num
);
776 xsnprintf(out
, sizeof out
, "%s", s
);
778 case OPTIONS_TABLE_ATTRIBUTES
:
779 s
= attributes_tostring(o
->num
);
780 xsnprintf(out
, sizeof out
, "%s", s
);
782 case OPTIONS_TABLE_FLAG
:
784 strlcpy(out
, "on", sizeof out
);
786 strlcpy(out
, "off", sizeof out
);
788 case OPTIONS_TABLE_CHOICE
:
789 s
= oe
->choices
[o
->num
];
790 xsnprintf(out
, sizeof out
, "%s", s
);
796 /* Find an option. */
799 const char *optstr
, const struct options_table_entry
**table
,
800 const struct options_table_entry
**oe
)
802 static const struct options_table_entry
*tables
[] = {
803 server_options_table
,
804 window_options_table
,
805 session_options_table
807 const struct options_table_entry
*oe_loop
;
810 for (i
= 0; i
< nitems(tables
); i
++) {
811 for (oe_loop
= tables
[i
]; oe_loop
->name
!= NULL
; oe_loop
++) {
812 if (strncmp(oe_loop
->name
, optstr
, strlen(optstr
)) != 0)
815 /* If already found, ambiguous. */
821 /* Bail now if an exact match. */
822 if (strcmp((*oe
)->name
, optstr
) == 0)