Add an option to trigger the terminal bell when there is an alert, from
[tmux-openbsd.git] / options-table.c
blob4a38505177b6f0f10310b9622fbb43c061a118ed
1 /* $OpenBSD$ */
3 /*
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>
21 #include <string.h>
22 #include <paths.h>
24 #include "tmux.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[] = {
37 "emacs", "vi", NULL
39 const char *options_table_clock_mode_style_list[] = {
40 "12", "24", NULL
42 const char *options_table_status_keys_list[] = {
43 "emacs", "vi", NULL
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
52 /* Server options. */
53 const struct options_table_entry server_options_table[] = {
54 { .name = "buffer-limit",
55 .type = OPTIONS_TABLE_NUMBER,
56 .minimum = 1,
57 .maximum = INT_MAX,
58 .default_num = 20
61 { .name = "escape-time",
62 .type = OPTIONS_TABLE_NUMBER,
63 .minimum = 0,
64 .maximum = INT_MAX,
65 .default_num = 500
68 { .name = "exit-unattached",
69 .type = OPTIONS_TABLE_FLAG,
70 .default_num = 0
73 { .name = "quiet",
74 .type = OPTIONS_TABLE_FLAG,
75 .default_num = 0 /* overridden in main() */
78 { .name = "set-clipboard",
79 .type = OPTIONS_TABLE_FLAG,
80 .default_num = 1
83 { .name = NULL }
86 /* Session options. */
87 const struct options_table_entry session_options_table[] = {
88 { .name = "base-index",
89 .type = OPTIONS_TABLE_NUMBER,
90 .minimum = 0,
91 .maximum = INT_MAX,
92 .default_num = 0
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,
103 .default_num = 0
106 { .name = "default-command",
107 .type = OPTIONS_TABLE_STRING,
108 .default_str = ""
111 { .name = "default-path",
112 .type = OPTIONS_TABLE_STRING,
113 .default_str = ""
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,
128 .default_num = 0
131 { .name = "detach-on-destroy",
132 .type = OPTIONS_TABLE_FLAG,
133 .default_num = 1
136 { .name = "display-panes-active-colour",
137 .type = OPTIONS_TABLE_COLOUR,
138 .default_num = 1
141 { .name = "display-panes-colour",
142 .type = OPTIONS_TABLE_COLOUR,
143 .default_num = 4
146 { .name = "display-panes-time",
147 .type = OPTIONS_TABLE_NUMBER,
148 .minimum = 1,
149 .maximum = INT_MAX,
150 .default_num = 1000
153 { .name = "display-time",
154 .type = OPTIONS_TABLE_NUMBER,
155 .minimum = 1,
156 .maximum = INT_MAX,
157 .default_num = 750
160 { .name = "history-limit",
161 .type = OPTIONS_TABLE_NUMBER,
162 .minimum = 0,
163 .maximum = INT_MAX,
164 .default_num = 2000
167 { .name = "lock-after-time",
168 .type = OPTIONS_TABLE_NUMBER,
169 .minimum = 0,
170 .maximum = INT_MAX,
171 .default_num = 0
174 { .name = "lock-command",
175 .type = OPTIONS_TABLE_STRING,
176 .default_str = "lock -np"
179 { .name = "lock-server",
180 .type = OPTIONS_TABLE_FLAG,
181 .default_num = 1
184 { .name = "message-attr",
185 .type = OPTIONS_TABLE_ATTRIBUTES,
186 .default_num = 0
189 { .name = "message-bg",
190 .type = OPTIONS_TABLE_COLOUR,
191 .default_num = 3
194 { .name = "message-fg",
195 .type = OPTIONS_TABLE_COLOUR,
196 .default_num = 0
199 { .name = "message-limit",
200 .type = OPTIONS_TABLE_NUMBER,
201 .minimum = 0,
202 .maximum = INT_MAX,
203 .default_num = 20
206 { .name = "mouse-resize-pane",
207 .type = OPTIONS_TABLE_FLAG,
208 .default_num = 0
211 { .name = "mouse-select-pane",
212 .type = OPTIONS_TABLE_FLAG,
213 .default_num = 0
216 { .name = "mouse-select-window",
217 .type = OPTIONS_TABLE_FLAG,
218 .default_num = 0
221 { .name = "mouse-utf8",
222 .type = OPTIONS_TABLE_FLAG,
223 .default_num = 0
226 { .name = "pane-active-border-bg",
227 .type = OPTIONS_TABLE_COLOUR,
228 .default_num = 8
231 { .name = "pane-active-border-fg",
232 .type = OPTIONS_TABLE_COLOUR,
233 .default_num = 2
236 { .name = "pane-border-bg",
237 .type = OPTIONS_TABLE_COLOUR,
238 .default_num = 8
241 { .name = "pane-border-fg",
242 .type = OPTIONS_TABLE_COLOUR,
243 .default_num = 8
246 { .name = "prefix",
247 .type = OPTIONS_TABLE_KEYS,
248 /* set in main() */
251 { .name = "repeat-time",
252 .type = OPTIONS_TABLE_NUMBER,
253 .minimum = 0,
254 .maximum = SHRT_MAX,
255 .default_num = 500
258 { .name = "set-remain-on-exit",
259 .type = OPTIONS_TABLE_FLAG,
260 .default_num = 0
263 { .name = "set-titles",
264 .type = OPTIONS_TABLE_FLAG,
265 .default_num = 0
268 { .name = "set-titles-string",
269 .type = OPTIONS_TABLE_STRING,
270 .default_str = "#S:#I:#W - \"#T\""
273 { .name = "status",
274 .type = OPTIONS_TABLE_FLAG,
275 .default_num = 1
278 { .name = "status-attr",
279 .type = OPTIONS_TABLE_ATTRIBUTES,
280 .default_num = 0
283 { .name = "status-bg",
284 .type = OPTIONS_TABLE_COLOUR,
285 .default_num = 2
288 { .name = "status-fg",
289 .type = OPTIONS_TABLE_COLOUR,
290 .default_num = 0
293 { .name = "status-interval",
294 .type = OPTIONS_TABLE_NUMBER,
295 .minimum = 0,
296 .maximum = INT_MAX,
297 .default_num = 15
300 { .name = "status-justify",
301 .type = OPTIONS_TABLE_CHOICE,
302 .choices = options_table_status_justify_list,
303 .default_num = 0
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,
319 .default_num = 0
322 { .name = "status-left-bg",
323 .type = OPTIONS_TABLE_COLOUR,
324 .default_num = 8
327 { .name = "status-left-fg",
328 .type = OPTIONS_TABLE_COLOUR,
329 .default_num = 8
332 { .name = "status-left-length",
333 .type = OPTIONS_TABLE_NUMBER,
334 .minimum = 0,
335 .maximum = SHRT_MAX,
336 .default_num = 10
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,
346 .default_num = 0
349 { .name = "status-right-bg",
350 .type = OPTIONS_TABLE_COLOUR,
351 .default_num = 8
354 { .name = "status-right-fg",
355 .type = OPTIONS_TABLE_COLOUR,
356 .default_num = 8
359 { .name = "status-right-length",
360 .type = OPTIONS_TABLE_NUMBER,
361 .minimum = 0,
362 .maximum = SHRT_MAX,
363 .default_num = 40
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,
388 .default_num = 0
391 { .name = "visual-bell",
392 .type = OPTIONS_TABLE_FLAG,
393 .default_num = 0
396 { .name = "visual-content",
397 .type = OPTIONS_TABLE_FLAG,
398 .default_num = 0
401 { .name = "visual-silence",
402 .type = OPTIONS_TABLE_FLAG,
403 .default_num = 0
406 { .name = NULL }
409 /* Window options. */
410 const struct options_table_entry window_options_table[] = {
411 { .name = "aggressive-resize",
412 .type = OPTIONS_TABLE_FLAG,
413 .default_num = 0
416 { .name = "alternate-screen",
417 .type = OPTIONS_TABLE_FLAG,
418 .default_num = 1
421 { .name = "automatic-rename",
422 .type = OPTIONS_TABLE_FLAG,
423 .default_num = 1
426 { .name = "clock-mode-colour",
427 .type = OPTIONS_TABLE_COLOUR,
428 .default_num = 4
431 { .name = "clock-mode-style",
432 .type = OPTIONS_TABLE_CHOICE,
433 .choices = options_table_clock_mode_style_list,
434 .default_num = 1
437 { .name = "force-height",
438 .type = OPTIONS_TABLE_NUMBER,
439 .minimum = 0,
440 .maximum = INT_MAX,
441 .default_num = 0
444 { .name = "force-width",
445 .type = OPTIONS_TABLE_NUMBER,
446 .minimum = 0,
447 .maximum = INT_MAX,
448 .default_num = 0
451 { .name = "main-pane-height",
452 .type = OPTIONS_TABLE_NUMBER,
453 .minimum = 1,
454 .maximum = INT_MAX,
455 .default_num = 24
458 { .name = "main-pane-width",
459 .type = OPTIONS_TABLE_NUMBER,
460 .minimum = 1,
461 .maximum = INT_MAX,
462 .default_num = 80
465 { .name = "mode-attr",
466 .type = OPTIONS_TABLE_ATTRIBUTES,
467 .default_num = 0
470 { .name = "mode-bg",
471 .type = OPTIONS_TABLE_COLOUR,
472 .default_num = 3
475 { .name = "mode-fg",
476 .type = OPTIONS_TABLE_COLOUR,
477 .default_num = 0
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,
488 .default_num = 0
491 { .name = "monitor-activity",
492 .type = OPTIONS_TABLE_FLAG,
493 .default_num = 0
496 { .name = "monitor-content",
497 .type = OPTIONS_TABLE_STRING,
498 .default_str = ""
501 { .name = "monitor-silence",
502 .type = OPTIONS_TABLE_NUMBER,
503 .minimum = 0,
504 .maximum = INT_MAX,
505 .default_num = 0
508 { .name = "other-pane-height",
509 .type = OPTIONS_TABLE_NUMBER,
510 .minimum = 0,
511 .maximum = INT_MAX,
512 .default_num = 0
515 { .name = "other-pane-width",
516 .type = OPTIONS_TABLE_NUMBER,
517 .minimum = 0,
518 .maximum = INT_MAX,
519 .default_num = 0
522 { .name = "remain-on-exit",
523 .type = OPTIONS_TABLE_FLAG,
524 .default_num = 0
527 { .name = "synchronize-panes",
528 .type = OPTIONS_TABLE_FLAG,
529 .default_num = 0
532 { .name = "utf8",
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,
544 .default_num = 8
547 { .name = "window-status-alert-fg",
548 .type = OPTIONS_TABLE_COLOUR,
549 .default_num = 8
552 { .name = "window-status-attr",
553 .type = OPTIONS_TABLE_ATTRIBUTES,
554 .default_num = 0
557 { .name = "window-status-bg",
558 .type = OPTIONS_TABLE_COLOUR,
559 .default_num = 8
562 { .name = "window-status-current-attr",
563 .type = OPTIONS_TABLE_ATTRIBUTES,
564 .default_num = 0
567 { .name = "window-status-current-bg",
568 .type = OPTIONS_TABLE_COLOUR,
569 .default_num = 8
572 { .name = "window-status-current-fg",
573 .type = OPTIONS_TABLE_COLOUR,
574 .default_num = 8
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,
584 .default_num = 8
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,
599 .default_num = 0
602 { .name = NULL }
605 /* Populate an options tree from a table. */
606 void
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);
615 else
616 options_set_number(oo, oe->name, oe->default_num);
620 /* Print an option using its type from the table. */
621 const char *
622 options_table_print_entry(
623 const struct options_table_entry *oe, struct options_entry *o)
625 static char out[BUFSIZ];
626 const char *s;
627 struct keylist *keylist;
628 u_int i;
630 *out = '\0';
631 switch (oe->type) {
632 case OPTIONS_TABLE_STRING:
633 xsnprintf(out, sizeof out, "\"%s\"", o->str);
634 break;
635 case OPTIONS_TABLE_NUMBER:
636 xsnprintf(out, sizeof out, "%lld", o->num);
637 break;
638 case OPTIONS_TABLE_KEYS:
639 keylist = o->data;
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);
646 break;
647 case OPTIONS_TABLE_COLOUR:
648 s = colour_tostring(o->num);
649 xsnprintf(out, sizeof out, "%s", s);
650 break;
651 case OPTIONS_TABLE_ATTRIBUTES:
652 s = attributes_tostring(o->num);
653 xsnprintf(out, sizeof out, "%s", s);
654 break;
655 case OPTIONS_TABLE_FLAG:
656 if (o->num)
657 strlcpy(out, "on", sizeof out);
658 else
659 strlcpy(out, "off", sizeof out);
660 break;
661 case OPTIONS_TABLE_CHOICE:
662 s = oe->choices[o->num];
663 xsnprintf(out, sizeof out, "%s", s);
664 break;
666 return (out);