Remove some code not needed on OpenBSD.
[tmux-openbsd.git] / options-table.c
blobc4ada1f24f09e90ec7e589232dd149b14106f8f4
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_mode_mouse_list[] = {
40 "off", "on", "copy-mode", NULL
42 const char *options_table_clock_mode_style_list[] = {
43 "12", "24", NULL
45 const char *options_table_status_keys_list[] = {
46 "emacs", "vi", NULL
48 const char *options_table_status_justify_list[] = {
49 "left", "centre", "right", NULL
51 const char *options_table_status_position_list[] = {
52 "top", "bottom", NULL
54 const char *options_table_bell_action_list[] = {
55 "none", "any", "current", NULL
58 /* Server options. */
59 const struct options_table_entry server_options_table[] = {
60 { .name = "buffer-limit",
61 .type = OPTIONS_TABLE_NUMBER,
62 .minimum = 1,
63 .maximum = INT_MAX,
64 .default_num = 20
67 { .name = "escape-time",
68 .type = OPTIONS_TABLE_NUMBER,
69 .minimum = 0,
70 .maximum = INT_MAX,
71 .default_num = 500
74 { .name = "exit-unattached",
75 .type = OPTIONS_TABLE_FLAG,
76 .default_num = 0
79 { .name = "quiet",
80 .type = OPTIONS_TABLE_FLAG,
81 .default_num = 0 /* overridden in main() */
84 { .name = "set-clipboard",
85 .type = OPTIONS_TABLE_FLAG,
86 .default_num = 1
89 { .name = NULL }
92 /* Session options. */
93 const struct options_table_entry session_options_table[] = {
94 { .name = "assume-paste-time",
95 .type = OPTIONS_TABLE_NUMBER,
96 .minimum = 0,
97 .maximum = INT_MAX,
98 .default_num = 1,
101 { .name = "base-index",
102 .type = OPTIONS_TABLE_NUMBER,
103 .minimum = 0,
104 .maximum = INT_MAX,
105 .default_num = 0
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,
116 .default_num = 0
119 { .name = "default-command",
120 .type = OPTIONS_TABLE_STRING,
121 .default_str = ""
124 { .name = "default-path",
125 .type = OPTIONS_TABLE_STRING,
126 .default_str = ""
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,
141 .default_num = 0
144 { .name = "detach-on-destroy",
145 .type = OPTIONS_TABLE_FLAG,
146 .default_num = 1
149 { .name = "display-panes-active-colour",
150 .type = OPTIONS_TABLE_COLOUR,
151 .default_num = 1
154 { .name = "display-panes-colour",
155 .type = OPTIONS_TABLE_COLOUR,
156 .default_num = 4
159 { .name = "display-panes-time",
160 .type = OPTIONS_TABLE_NUMBER,
161 .minimum = 1,
162 .maximum = INT_MAX,
163 .default_num = 1000
166 { .name = "display-time",
167 .type = OPTIONS_TABLE_NUMBER,
168 .minimum = 1,
169 .maximum = INT_MAX,
170 .default_num = 750
173 { .name = "history-limit",
174 .type = OPTIONS_TABLE_NUMBER,
175 .minimum = 0,
176 .maximum = INT_MAX,
177 .default_num = 2000
180 { .name = "lock-after-time",
181 .type = OPTIONS_TABLE_NUMBER,
182 .minimum = 0,
183 .maximum = INT_MAX,
184 .default_num = 0
187 { .name = "lock-command",
188 .type = OPTIONS_TABLE_STRING,
189 .default_str = "lock -np"
192 { .name = "lock-server",
193 .type = OPTIONS_TABLE_FLAG,
194 .default_num = 1
197 { .name = "message-attr",
198 .type = OPTIONS_TABLE_ATTRIBUTES,
199 .default_num = 0
202 { .name = "message-bg",
203 .type = OPTIONS_TABLE_COLOUR,
204 .default_num = 3
207 { .name = "message-command-attr",
208 .type = OPTIONS_TABLE_ATTRIBUTES,
209 .default_num = 0
212 { .name = "message-command-bg",
213 .type = OPTIONS_TABLE_COLOUR,
214 .default_num = 0
217 { .name = "message-command-fg",
218 .type = OPTIONS_TABLE_COLOUR,
219 .default_num = 3
222 { .name = "message-fg",
223 .type = OPTIONS_TABLE_COLOUR,
224 .default_num = 0
227 { .name = "message-limit",
228 .type = OPTIONS_TABLE_NUMBER,
229 .minimum = 0,
230 .maximum = INT_MAX,
231 .default_num = 20
234 { .name = "mouse-resize-pane",
235 .type = OPTIONS_TABLE_FLAG,
236 .default_num = 0
239 { .name = "mouse-select-pane",
240 .type = OPTIONS_TABLE_FLAG,
241 .default_num = 0
244 { .name = "mouse-select-window",
245 .type = OPTIONS_TABLE_FLAG,
246 .default_num = 0
249 { .name = "mouse-utf8",
250 .type = OPTIONS_TABLE_FLAG,
251 .default_num = 0
254 { .name = "pane-active-border-bg",
255 .type = OPTIONS_TABLE_COLOUR,
256 .default_num = 8
259 { .name = "pane-active-border-fg",
260 .type = OPTIONS_TABLE_COLOUR,
261 .default_num = 2
264 { .name = "pane-border-bg",
265 .type = OPTIONS_TABLE_COLOUR,
266 .default_num = 8
269 { .name = "pane-border-fg",
270 .type = OPTIONS_TABLE_COLOUR,
271 .default_num = 8
274 { .name = "prefix",
275 .type = OPTIONS_TABLE_KEY,
276 .default_num = '\002',
279 { .name = "prefix2",
280 .type = OPTIONS_TABLE_KEY,
281 .default_num = KEYC_NONE,
284 { .name = "renumber-windows",
285 .type = OPTIONS_TABLE_FLAG,
286 .default_num = 0
289 { .name = "repeat-time",
290 .type = OPTIONS_TABLE_NUMBER,
291 .minimum = 0,
292 .maximum = SHRT_MAX,
293 .default_num = 500
296 { .name = "set-remain-on-exit",
297 .type = OPTIONS_TABLE_FLAG,
298 .default_num = 0
301 { .name = "set-titles",
302 .type = OPTIONS_TABLE_FLAG,
303 .default_num = 0
306 { .name = "set-titles-string",
307 .type = OPTIONS_TABLE_STRING,
308 .default_str = "#S:#I:#W - \"#T\""
311 { .name = "status",
312 .type = OPTIONS_TABLE_FLAG,
313 .default_num = 1
316 { .name = "status-attr",
317 .type = OPTIONS_TABLE_ATTRIBUTES,
318 .default_num = 0
321 { .name = "status-bg",
322 .type = OPTIONS_TABLE_COLOUR,
323 .default_num = 2
326 { .name = "status-fg",
327 .type = OPTIONS_TABLE_COLOUR,
328 .default_num = 0
331 { .name = "status-interval",
332 .type = OPTIONS_TABLE_NUMBER,
333 .minimum = 0,
334 .maximum = INT_MAX,
335 .default_num = 15
338 { .name = "status-justify",
339 .type = OPTIONS_TABLE_CHOICE,
340 .choices = options_table_status_justify_list,
341 .default_num = 0
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,
357 .default_num = 0
360 { .name = "status-left-bg",
361 .type = OPTIONS_TABLE_COLOUR,
362 .default_num = 8
365 { .name = "status-left-fg",
366 .type = OPTIONS_TABLE_COLOUR,
367 .default_num = 8
370 { .name = "status-left-length",
371 .type = OPTIONS_TABLE_NUMBER,
372 .minimum = 0,
373 .maximum = SHRT_MAX,
374 .default_num = 10
377 { .name = "status-position",
378 .type = OPTIONS_TABLE_CHOICE,
379 .choices = options_table_status_position_list,
380 .default_num = 1
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,
390 .default_num = 0
393 { .name = "status-right-bg",
394 .type = OPTIONS_TABLE_COLOUR,
395 .default_num = 8
398 { .name = "status-right-fg",
399 .type = OPTIONS_TABLE_COLOUR,
400 .default_num = 8
403 { .name = "status-right-length",
404 .type = OPTIONS_TABLE_NUMBER,
405 .minimum = 0,
406 .maximum = SHRT_MAX,
407 .default_num = 40
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 = "*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,
432 .default_num = 0
435 { .name = "visual-bell",
436 .type = OPTIONS_TABLE_FLAG,
437 .default_num = 0
440 { .name = "visual-content",
441 .type = OPTIONS_TABLE_FLAG,
442 .default_num = 0
445 { .name = "visual-silence",
446 .type = OPTIONS_TABLE_FLAG,
447 .default_num = 0
450 { .name = "word-separators",
451 .type = OPTIONS_TABLE_STRING,
452 .default_str = " -_@"
455 { .name = NULL }
458 /* Window options. */
459 const struct options_table_entry window_options_table[] = {
460 { .name = "aggressive-resize",
461 .type = OPTIONS_TABLE_FLAG,
462 .default_num = 0
465 { .name = "allow-rename",
466 .type = OPTIONS_TABLE_FLAG,
467 .default_num = 1
470 { .name = "alternate-screen",
471 .type = OPTIONS_TABLE_FLAG,
472 .default_num = 1
475 { .name = "automatic-rename",
476 .type = OPTIONS_TABLE_FLAG,
477 .default_num = 1
480 { .name = "c0-change-trigger",
481 .type = OPTIONS_TABLE_NUMBER,
482 .default_num = 250,
483 .minimum = 0,
484 .maximum = USHRT_MAX
487 { .name = "c0-change-interval",
488 .type = OPTIONS_TABLE_NUMBER,
489 .default_num = 100,
490 .minimum = 1,
491 .maximum = USHRT_MAX
494 { .name = "clock-mode-colour",
495 .type = OPTIONS_TABLE_COLOUR,
496 .default_num = 4
499 { .name = "clock-mode-style",
500 .type = OPTIONS_TABLE_CHOICE,
501 .choices = options_table_clock_mode_style_list,
502 .default_num = 1
505 { .name = "force-height",
506 .type = OPTIONS_TABLE_NUMBER,
507 .minimum = 0,
508 .maximum = INT_MAX,
509 .default_num = 0
512 { .name = "force-width",
513 .type = OPTIONS_TABLE_NUMBER,
514 .minimum = 0,
515 .maximum = INT_MAX,
516 .default_num = 0
519 { .name = "main-pane-height",
520 .type = OPTIONS_TABLE_NUMBER,
521 .minimum = 1,
522 .maximum = INT_MAX,
523 .default_num = 24
526 { .name = "main-pane-width",
527 .type = OPTIONS_TABLE_NUMBER,
528 .minimum = 1,
529 .maximum = INT_MAX,
530 .default_num = 80
533 { .name = "mode-attr",
534 .type = OPTIONS_TABLE_ATTRIBUTES,
535 .default_num = 0
538 { .name = "mode-bg",
539 .type = OPTIONS_TABLE_COLOUR,
540 .default_num = 3
543 { .name = "mode-fg",
544 .type = OPTIONS_TABLE_COLOUR,
545 .default_num = 0
548 { .name = "mode-keys",
549 .type = OPTIONS_TABLE_CHOICE,
550 .choices = options_table_mode_keys_list,
551 .default_num = MODEKEY_EMACS
554 { .name = "mode-mouse",
555 .type = OPTIONS_TABLE_CHOICE,
556 .choices = options_table_mode_mouse_list,
557 .default_num = 0
560 { .name = "monitor-activity",
561 .type = OPTIONS_TABLE_FLAG,
562 .default_num = 0
565 { .name = "monitor-content",
566 .type = OPTIONS_TABLE_STRING,
567 .default_str = ""
570 { .name = "monitor-silence",
571 .type = OPTIONS_TABLE_NUMBER,
572 .minimum = 0,
573 .maximum = INT_MAX,
574 .default_num = 0
577 { .name = "other-pane-height",
578 .type = OPTIONS_TABLE_NUMBER,
579 .minimum = 0,
580 .maximum = INT_MAX,
581 .default_num = 0
584 { .name = "other-pane-width",
585 .type = OPTIONS_TABLE_NUMBER,
586 .minimum = 0,
587 .maximum = INT_MAX,
588 .default_num = 0
591 { .name = "pane-base-index",
592 .type = OPTIONS_TABLE_NUMBER,
593 .minimum = 0,
594 .maximum = USHRT_MAX,
595 .default_num = 0
598 { .name = "remain-on-exit",
599 .type = OPTIONS_TABLE_FLAG,
600 .default_num = 0
603 { .name = "synchronize-panes",
604 .type = OPTIONS_TABLE_FLAG,
605 .default_num = 0
608 { .name = "utf8",
609 .type = OPTIONS_TABLE_FLAG,
610 .default_num = 0 /* overridden in main() */
613 { .name = "window-status-activity-attr",
614 .type = OPTIONS_TABLE_ATTRIBUTES,
615 .default_num = GRID_ATTR_REVERSE
618 { .name = "window-status-activity-bg",
619 .type = OPTIONS_TABLE_COLOUR,
620 .default_num = 8
623 { .name = "window-status-activity-fg",
624 .type = OPTIONS_TABLE_COLOUR,
625 .default_num = 8
628 { .name = "window-status-bell-attr",
629 .type = OPTIONS_TABLE_ATTRIBUTES,
630 .default_num = GRID_ATTR_REVERSE
633 { .name = "window-status-bell-bg",
634 .type = OPTIONS_TABLE_COLOUR,
635 .default_num = 8
638 { .name = "window-status-bell-fg",
639 .type = OPTIONS_TABLE_COLOUR,
640 .default_num = 8
643 { .name = "window-status-content-attr",
644 .type = OPTIONS_TABLE_ATTRIBUTES,
645 .default_num = GRID_ATTR_REVERSE
648 { .name = "window-status-content-bg",
649 .type = OPTIONS_TABLE_COLOUR,
650 .default_num = 8
653 { .name = "window-status-content-fg",
654 .type = OPTIONS_TABLE_COLOUR,
655 .default_num = 8
658 { .name = "window-status-attr",
659 .type = OPTIONS_TABLE_ATTRIBUTES,
660 .default_num = 0
663 { .name = "window-status-bg",
664 .type = OPTIONS_TABLE_COLOUR,
665 .default_num = 8
668 { .name = "window-status-current-attr",
669 .type = OPTIONS_TABLE_ATTRIBUTES,
670 .default_num = 0
673 { .name = "window-status-current-bg",
674 .type = OPTIONS_TABLE_COLOUR,
675 .default_num = 8
678 { .name = "window-status-current-fg",
679 .type = OPTIONS_TABLE_COLOUR,
680 .default_num = 8
683 { .name = "window-status-current-format",
684 .type = OPTIONS_TABLE_STRING,
685 .default_str = "#I:#W#F"
688 { .name = "window-status-last-attr",
689 .type = OPTIONS_TABLE_ATTRIBUTES,
690 .default_num = 0
693 { .name = "window-status-last-bg",
694 .type = OPTIONS_TABLE_COLOUR,
695 .default_num = 8
698 { .name = "window-status-last-fg",
699 .type = OPTIONS_TABLE_COLOUR,
700 .default_num = 8
703 { .name = "window-status-fg",
704 .type = OPTIONS_TABLE_COLOUR,
705 .default_num = 8
708 { .name = "window-status-format",
709 .type = OPTIONS_TABLE_STRING,
710 .default_str = "#I:#W#F"
713 { .name = "window-status-separator",
714 .type = OPTIONS_TABLE_STRING,
715 .default_str = " "
718 { .name = "wrap-search",
719 .type = OPTIONS_TABLE_FLAG,
720 .default_num = 1
723 { .name = "xterm-keys",
724 .type = OPTIONS_TABLE_FLAG,
725 .default_num = 0
728 { .name = NULL }
731 /* Populate an options tree from a table. */
732 void
733 options_table_populate_tree(
734 const struct options_table_entry *table, struct options *oo)
736 const struct options_table_entry *oe;
738 for (oe = table; oe->name != NULL; oe++) {
739 if (oe->default_str != NULL)
740 options_set_string(oo, oe->name, "%s", oe->default_str);
741 else
742 options_set_number(oo, oe->name, oe->default_num);
746 /* Print an option using its type from the table. */
747 const char *
748 options_table_print_entry(const struct options_table_entry *oe,
749 struct options_entry *o, int no_quotes)
751 static char out[BUFSIZ];
752 const char *s;
754 *out = '\0';
755 switch (oe->type) {
756 case OPTIONS_TABLE_STRING:
757 if (no_quotes)
758 xsnprintf(out, sizeof out, "%s", o->str);
759 else
760 xsnprintf(out, sizeof out, "\"%s\"", o->str);
761 break;
762 case OPTIONS_TABLE_NUMBER:
763 xsnprintf(out, sizeof out, "%lld", o->num);
764 break;
765 case OPTIONS_TABLE_KEY:
766 xsnprintf(out, sizeof out, "%s",
767 key_string_lookup_key(o->num));
768 break;
769 case OPTIONS_TABLE_COLOUR:
770 s = colour_tostring(o->num);
771 xsnprintf(out, sizeof out, "%s", s);
772 break;
773 case OPTIONS_TABLE_ATTRIBUTES:
774 s = attributes_tostring(o->num);
775 xsnprintf(out, sizeof out, "%s", s);
776 break;
777 case OPTIONS_TABLE_FLAG:
778 if (o->num)
779 strlcpy(out, "on", sizeof out);
780 else
781 strlcpy(out, "off", sizeof out);
782 break;
783 case OPTIONS_TABLE_CHOICE:
784 s = oe->choices[o->num];
785 xsnprintf(out, sizeof out, "%s", s);
786 break;
788 return (out);
791 /* Find an option. */
793 options_table_find(
794 const char *optstr, const struct options_table_entry **table,
795 const struct options_table_entry **oe)
797 static const struct options_table_entry *tables[] = {
798 server_options_table,
799 window_options_table,
800 session_options_table
802 const struct options_table_entry *oe_loop;
803 u_int i;
805 for (i = 0; i < nitems(tables); i++) {
806 for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
807 if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
808 continue;
810 /* If already found, ambiguous. */
811 if (*oe != NULL)
812 return (-1);
813 *oe = oe_loop;
814 *table = tables[i];
816 /* Bail now if an exact match. */
817 if (strcmp((*oe)->name, optstr) == 0)
818 break;
821 return (0);