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() */
78 { .name
= "set-clipboard",
79 .type
= OPTIONS_TABLE_FLAG
,
86 /* Session options. */
87 const struct options_table_entry session_options_table
[] = {
88 { .name
= "base-index",
89 .type
= OPTIONS_TABLE_NUMBER
,
95 { .name
= "bell-action",
96 .type
= OPTIONS_TABLE_CHOICE
,
97 .choices
= options_table_bell_action_list
,
98 .default_num
= BELL_ANY
101 { .name
= "bell-on-alert",
102 .type
= OPTIONS_TABLE_FLAG
,
106 { .name
= "default-command",
107 .type
= OPTIONS_TABLE_STRING
,
111 { .name
= "default-path",
112 .type
= OPTIONS_TABLE_STRING
,
116 { .name
= "default-shell",
117 .type
= OPTIONS_TABLE_STRING
,
118 .default_str
= _PATH_BSHELL
121 { .name
= "default-terminal",
122 .type
= OPTIONS_TABLE_STRING
,
123 .default_str
= "screen"
126 { .name
= "destroy-unattached",
127 .type
= OPTIONS_TABLE_FLAG
,
131 { .name
= "detach-on-destroy",
132 .type
= OPTIONS_TABLE_FLAG
,
136 { .name
= "display-panes-active-colour",
137 .type
= OPTIONS_TABLE_COLOUR
,
141 { .name
= "display-panes-colour",
142 .type
= OPTIONS_TABLE_COLOUR
,
146 { .name
= "display-panes-time",
147 .type
= OPTIONS_TABLE_NUMBER
,
153 { .name
= "display-time",
154 .type
= OPTIONS_TABLE_NUMBER
,
160 { .name
= "history-limit",
161 .type
= OPTIONS_TABLE_NUMBER
,
167 { .name
= "lock-after-time",
168 .type
= OPTIONS_TABLE_NUMBER
,
174 { .name
= "lock-command",
175 .type
= OPTIONS_TABLE_STRING
,
176 .default_str
= "lock -np"
179 { .name
= "lock-server",
180 .type
= OPTIONS_TABLE_FLAG
,
184 { .name
= "message-attr",
185 .type
= OPTIONS_TABLE_ATTRIBUTES
,
189 { .name
= "message-bg",
190 .type
= OPTIONS_TABLE_COLOUR
,
194 { .name
= "message-fg",
195 .type
= OPTIONS_TABLE_COLOUR
,
199 { .name
= "message-limit",
200 .type
= OPTIONS_TABLE_NUMBER
,
206 { .name
= "mouse-resize-pane",
207 .type
= OPTIONS_TABLE_FLAG
,
211 { .name
= "mouse-select-pane",
212 .type
= OPTIONS_TABLE_FLAG
,
216 { .name
= "mouse-select-window",
217 .type
= OPTIONS_TABLE_FLAG
,
221 { .name
= "mouse-utf8",
222 .type
= OPTIONS_TABLE_FLAG
,
226 { .name
= "pane-active-border-bg",
227 .type
= OPTIONS_TABLE_COLOUR
,
231 { .name
= "pane-active-border-fg",
232 .type
= OPTIONS_TABLE_COLOUR
,
236 { .name
= "pane-border-bg",
237 .type
= OPTIONS_TABLE_COLOUR
,
241 { .name
= "pane-border-fg",
242 .type
= OPTIONS_TABLE_COLOUR
,
247 .type
= OPTIONS_TABLE_KEYS
,
251 { .name
= "repeat-time",
252 .type
= OPTIONS_TABLE_NUMBER
,
258 { .name
= "set-remain-on-exit",
259 .type
= OPTIONS_TABLE_FLAG
,
263 { .name
= "set-titles",
264 .type
= OPTIONS_TABLE_FLAG
,
268 { .name
= "set-titles-string",
269 .type
= OPTIONS_TABLE_STRING
,
270 .default_str
= "#S:#I:#W - \"#T\""
274 .type
= OPTIONS_TABLE_FLAG
,
278 { .name
= "status-attr",
279 .type
= OPTIONS_TABLE_ATTRIBUTES
,
283 { .name
= "status-bg",
284 .type
= OPTIONS_TABLE_COLOUR
,
288 { .name
= "status-fg",
289 .type
= OPTIONS_TABLE_COLOUR
,
293 { .name
= "status-interval",
294 .type
= OPTIONS_TABLE_NUMBER
,
300 { .name
= "status-justify",
301 .type
= OPTIONS_TABLE_CHOICE
,
302 .choices
= options_table_status_justify_list
,
306 { .name
= "status-keys",
307 .type
= OPTIONS_TABLE_CHOICE
,
308 .choices
= options_table_status_keys_list
,
309 .default_num
= MODEKEY_EMACS
312 { .name
= "status-left",
313 .type
= OPTIONS_TABLE_STRING
,
314 .default_str
= "[#S]"
317 { .name
= "status-left-attr",
318 .type
= OPTIONS_TABLE_ATTRIBUTES
,
322 { .name
= "status-left-bg",
323 .type
= OPTIONS_TABLE_COLOUR
,
327 { .name
= "status-left-fg",
328 .type
= OPTIONS_TABLE_COLOUR
,
332 { .name
= "status-left-length",
333 .type
= OPTIONS_TABLE_NUMBER
,
339 { .name
= "status-right",
340 .type
= OPTIONS_TABLE_STRING
,
341 .default_str
= "\"#22T\" %H:%M %d-%b-%y"
344 { .name
= "status-right-attr",
345 .type
= OPTIONS_TABLE_ATTRIBUTES
,
349 { .name
= "status-right-bg",
350 .type
= OPTIONS_TABLE_COLOUR
,
354 { .name
= "status-right-fg",
355 .type
= OPTIONS_TABLE_COLOUR
,
359 { .name
= "status-right-length",
360 .type
= OPTIONS_TABLE_NUMBER
,
366 { .name
= "status-utf8",
367 .type
= OPTIONS_TABLE_FLAG
,
368 .default_num
= 0 /* overridden in main() */
371 { .name
= "terminal-overrides",
372 .type
= OPTIONS_TABLE_STRING
,
373 .default_str
= "*88col*:colors=88,*256col*:colors=256"
374 ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
375 ":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
376 ":Cs=\\E[%p1%d q:Csr=\\E[2 q"
379 { .name
= "update-environment",
380 .type
= OPTIONS_TABLE_STRING
,
381 .default_str
= "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
382 "SSH_CONNECTION WINDOWID XAUTHORITY"
386 { .name
= "visual-activity",
387 .type
= OPTIONS_TABLE_FLAG
,
391 { .name
= "visual-bell",
392 .type
= OPTIONS_TABLE_FLAG
,
396 { .name
= "visual-content",
397 .type
= OPTIONS_TABLE_FLAG
,
401 { .name
= "visual-silence",
402 .type
= OPTIONS_TABLE_FLAG
,
409 /* Window options. */
410 const struct options_table_entry window_options_table
[] = {
411 { .name
= "aggressive-resize",
412 .type
= OPTIONS_TABLE_FLAG
,
416 { .name
= "alternate-screen",
417 .type
= OPTIONS_TABLE_FLAG
,
421 { .name
= "automatic-rename",
422 .type
= OPTIONS_TABLE_FLAG
,
426 { .name
= "clock-mode-colour",
427 .type
= OPTIONS_TABLE_COLOUR
,
431 { .name
= "clock-mode-style",
432 .type
= OPTIONS_TABLE_CHOICE
,
433 .choices
= options_table_clock_mode_style_list
,
437 { .name
= "force-height",
438 .type
= OPTIONS_TABLE_NUMBER
,
444 { .name
= "force-width",
445 .type
= OPTIONS_TABLE_NUMBER
,
451 { .name
= "main-pane-height",
452 .type
= OPTIONS_TABLE_NUMBER
,
458 { .name
= "main-pane-width",
459 .type
= OPTIONS_TABLE_NUMBER
,
465 { .name
= "mode-attr",
466 .type
= OPTIONS_TABLE_ATTRIBUTES
,
471 .type
= OPTIONS_TABLE_COLOUR
,
476 .type
= OPTIONS_TABLE_COLOUR
,
480 { .name
= "mode-keys",
481 .type
= OPTIONS_TABLE_CHOICE
,
482 .choices
= options_table_mode_keys_list
,
483 .default_num
= MODEKEY_EMACS
486 { .name
= "mode-mouse",
487 .type
= OPTIONS_TABLE_FLAG
,
491 { .name
= "monitor-activity",
492 .type
= OPTIONS_TABLE_FLAG
,
496 { .name
= "monitor-content",
497 .type
= OPTIONS_TABLE_STRING
,
501 { .name
= "monitor-silence",
502 .type
= OPTIONS_TABLE_NUMBER
,
508 { .name
= "other-pane-height",
509 .type
= OPTIONS_TABLE_NUMBER
,
515 { .name
= "other-pane-width",
516 .type
= OPTIONS_TABLE_NUMBER
,
522 { .name
= "remain-on-exit",
523 .type
= OPTIONS_TABLE_FLAG
,
527 { .name
= "synchronize-panes",
528 .type
= OPTIONS_TABLE_FLAG
,
533 .type
= OPTIONS_TABLE_FLAG
,
534 .default_num
= 0 /* overridden in main() */
537 { .name
= "window-status-alert-attr",
538 .type
= OPTIONS_TABLE_ATTRIBUTES
,
539 .default_num
= GRID_ATTR_REVERSE
542 { .name
= "window-status-alert-bg",
543 .type
= OPTIONS_TABLE_COLOUR
,
547 { .name
= "window-status-alert-fg",
548 .type
= OPTIONS_TABLE_COLOUR
,
552 { .name
= "window-status-attr",
553 .type
= OPTIONS_TABLE_ATTRIBUTES
,
557 { .name
= "window-status-bg",
558 .type
= OPTIONS_TABLE_COLOUR
,
562 { .name
= "window-status-current-attr",
563 .type
= OPTIONS_TABLE_ATTRIBUTES
,
567 { .name
= "window-status-current-bg",
568 .type
= OPTIONS_TABLE_COLOUR
,
572 { .name
= "window-status-current-fg",
573 .type
= OPTIONS_TABLE_COLOUR
,
577 { .name
= "window-status-current-format",
578 .type
= OPTIONS_TABLE_STRING
,
579 .default_str
= "#I:#W#F"
582 { .name
= "window-status-fg",
583 .type
= OPTIONS_TABLE_COLOUR
,
587 { .name
= "window-status-format",
588 .type
= OPTIONS_TABLE_STRING
,
589 .default_str
= "#I:#W#F"
592 { .name
= "word-separators",
593 .type
= OPTIONS_TABLE_STRING
,
594 .default_str
= " -_@"
597 { .name
= "xterm-keys",
598 .type
= OPTIONS_TABLE_FLAG
,
605 /* Populate an options tree from a table. */
607 options_table_populate_tree(
608 const struct options_table_entry
*table
, struct options
*oo
)
610 const struct options_table_entry
*oe
;
612 for (oe
= table
; oe
->name
!= NULL
; oe
++) {
613 if (oe
->default_str
!= NULL
)
614 options_set_string(oo
, oe
->name
, "%s", oe
->default_str
);
616 options_set_number(oo
, oe
->name
, oe
->default_num
);
620 /* Print an option using its type from the table. */
622 options_table_print_entry(
623 const struct options_table_entry
*oe
, struct options_entry
*o
)
625 static char out
[BUFSIZ
];
627 struct keylist
*keylist
;
632 case OPTIONS_TABLE_STRING
:
633 xsnprintf(out
, sizeof out
, "\"%s\"", o
->str
);
635 case OPTIONS_TABLE_NUMBER
:
636 xsnprintf(out
, sizeof out
, "%lld", o
->num
);
638 case OPTIONS_TABLE_KEYS
:
640 for (i
= 0; i
< ARRAY_LENGTH(keylist
); i
++) {
641 s
= key_string_lookup_key(ARRAY_ITEM(keylist
, i
));
642 strlcat(out
, s
, sizeof out
);
643 if (i
!= ARRAY_LENGTH(keylist
) - 1)
644 strlcat(out
, ",", sizeof out
);
647 case OPTIONS_TABLE_COLOUR
:
648 s
= colour_tostring(o
->num
);
649 xsnprintf(out
, sizeof out
, "%s", s
);
651 case OPTIONS_TABLE_ATTRIBUTES
:
652 s
= attributes_tostring(o
->num
);
653 xsnprintf(out
, sizeof out
, "%s", s
);
655 case OPTIONS_TABLE_FLAG
:
657 strlcpy(out
, "on", sizeof out
);
659 strlcpy(out
, "off", sizeof out
);
661 case OPTIONS_TABLE_CHOICE
:
662 s
= oe
->choices
[o
->num
];
663 xsnprintf(out
, sizeof out
, "%s", s
);