Drop the ability to have a list of keys in the prefix in favour of two
[tmux-openbsd.git] / options-table.c
blob918a9f5123ff3aba5611055c75d890ed493cb541
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_bell_action_list[] = {
52 "none", "any", "current", NULL
55 /* Server options. */
56 const struct options_table_entry server_options_table[] = {
57 { .name = "buffer-limit",
58 .type = OPTIONS_TABLE_NUMBER,
59 .minimum = 1,
60 .maximum = INT_MAX,
61 .default_num = 20
64 { .name = "escape-time",
65 .type = OPTIONS_TABLE_NUMBER,
66 .minimum = 0,
67 .maximum = INT_MAX,
68 .default_num = 500
71 { .name = "exit-unattached",
72 .type = OPTIONS_TABLE_FLAG,
73 .default_num = 0
76 { .name = "quiet",
77 .type = OPTIONS_TABLE_FLAG,
78 .default_num = 0 /* overridden in main() */
81 { .name = "set-clipboard",
82 .type = OPTIONS_TABLE_FLAG,
83 .default_num = 1
86 { .name = NULL }
89 /* Session options. */
90 const struct options_table_entry session_options_table[] = {
91 { .name = "base-index",
92 .type = OPTIONS_TABLE_NUMBER,
93 .minimum = 0,
94 .maximum = INT_MAX,
95 .default_num = 0
98 { .name = "bell-action",
99 .type = OPTIONS_TABLE_CHOICE,
100 .choices = options_table_bell_action_list,
101 .default_num = BELL_ANY
104 { .name = "bell-on-alert",
105 .type = OPTIONS_TABLE_FLAG,
106 .default_num = 0
109 { .name = "default-command",
110 .type = OPTIONS_TABLE_STRING,
111 .default_str = ""
114 { .name = "default-path",
115 .type = OPTIONS_TABLE_STRING,
116 .default_str = ""
119 { .name = "default-shell",
120 .type = OPTIONS_TABLE_STRING,
121 .default_str = _PATH_BSHELL
124 { .name = "default-terminal",
125 .type = OPTIONS_TABLE_STRING,
126 .default_str = "screen"
129 { .name = "destroy-unattached",
130 .type = OPTIONS_TABLE_FLAG,
131 .default_num = 0
134 { .name = "detach-on-destroy",
135 .type = OPTIONS_TABLE_FLAG,
136 .default_num = 1
139 { .name = "display-panes-active-colour",
140 .type = OPTIONS_TABLE_COLOUR,
141 .default_num = 1
144 { .name = "display-panes-colour",
145 .type = OPTIONS_TABLE_COLOUR,
146 .default_num = 4
149 { .name = "display-panes-time",
150 .type = OPTIONS_TABLE_NUMBER,
151 .minimum = 1,
152 .maximum = INT_MAX,
153 .default_num = 1000
156 { .name = "display-time",
157 .type = OPTIONS_TABLE_NUMBER,
158 .minimum = 1,
159 .maximum = INT_MAX,
160 .default_num = 750
163 { .name = "history-limit",
164 .type = OPTIONS_TABLE_NUMBER,
165 .minimum = 0,
166 .maximum = INT_MAX,
167 .default_num = 2000
170 { .name = "lock-after-time",
171 .type = OPTIONS_TABLE_NUMBER,
172 .minimum = 0,
173 .maximum = INT_MAX,
174 .default_num = 0
177 { .name = "lock-command",
178 .type = OPTIONS_TABLE_STRING,
179 .default_str = "lock -np"
182 { .name = "lock-server",
183 .type = OPTIONS_TABLE_FLAG,
184 .default_num = 1
187 { .name = "message-attr",
188 .type = OPTIONS_TABLE_ATTRIBUTES,
189 .default_num = 0
192 { .name = "message-bg",
193 .type = OPTIONS_TABLE_COLOUR,
194 .default_num = 3
197 { .name = "message-command-attr",
198 .type = OPTIONS_TABLE_ATTRIBUTES,
199 .default_num = 0
202 { .name = "message-command-bg",
203 .type = OPTIONS_TABLE_COLOUR,
204 .default_num = 0
207 { .name = "message-command-fg",
208 .type = OPTIONS_TABLE_COLOUR,
209 .default_num = 3
212 { .name = "message-fg",
213 .type = OPTIONS_TABLE_COLOUR,
214 .default_num = 0
217 { .name = "message-limit",
218 .type = OPTIONS_TABLE_NUMBER,
219 .minimum = 0,
220 .maximum = INT_MAX,
221 .default_num = 20
224 { .name = "mouse-resize-pane",
225 .type = OPTIONS_TABLE_FLAG,
226 .default_num = 0
229 { .name = "mouse-select-pane",
230 .type = OPTIONS_TABLE_FLAG,
231 .default_num = 0
234 { .name = "mouse-select-window",
235 .type = OPTIONS_TABLE_FLAG,
236 .default_num = 0
239 { .name = "mouse-utf8",
240 .type = OPTIONS_TABLE_FLAG,
241 .default_num = 0
244 { .name = "pane-active-border-bg",
245 .type = OPTIONS_TABLE_COLOUR,
246 .default_num = 8
249 { .name = "pane-active-border-fg",
250 .type = OPTIONS_TABLE_COLOUR,
251 .default_num = 2
254 { .name = "pane-border-bg",
255 .type = OPTIONS_TABLE_COLOUR,
256 .default_num = 8
259 { .name = "pane-border-fg",
260 .type = OPTIONS_TABLE_COLOUR,
261 .default_num = 8
264 { .name = "prefix",
265 .type = OPTIONS_TABLE_KEY,
266 .default_num = '\002',
269 { .name = "prefix2",
270 .type = OPTIONS_TABLE_KEY,
271 .default_num = KEYC_NONE,
274 { .name = "repeat-time",
275 .type = OPTIONS_TABLE_NUMBER,
276 .minimum = 0,
277 .maximum = SHRT_MAX,
278 .default_num = 500
281 { .name = "set-remain-on-exit",
282 .type = OPTIONS_TABLE_FLAG,
283 .default_num = 0
286 { .name = "set-titles",
287 .type = OPTIONS_TABLE_FLAG,
288 .default_num = 0
291 { .name = "set-titles-string",
292 .type = OPTIONS_TABLE_STRING,
293 .default_str = "#S:#I:#W - \"#T\""
296 { .name = "status",
297 .type = OPTIONS_TABLE_FLAG,
298 .default_num = 1
301 { .name = "status-attr",
302 .type = OPTIONS_TABLE_ATTRIBUTES,
303 .default_num = 0
306 { .name = "status-bg",
307 .type = OPTIONS_TABLE_COLOUR,
308 .default_num = 2
311 { .name = "status-fg",
312 .type = OPTIONS_TABLE_COLOUR,
313 .default_num = 0
316 { .name = "status-interval",
317 .type = OPTIONS_TABLE_NUMBER,
318 .minimum = 0,
319 .maximum = INT_MAX,
320 .default_num = 15
323 { .name = "status-justify",
324 .type = OPTIONS_TABLE_CHOICE,
325 .choices = options_table_status_justify_list,
326 .default_num = 0
329 { .name = "status-keys",
330 .type = OPTIONS_TABLE_CHOICE,
331 .choices = options_table_status_keys_list,
332 .default_num = MODEKEY_EMACS
335 { .name = "status-left",
336 .type = OPTIONS_TABLE_STRING,
337 .default_str = "[#S]"
340 { .name = "status-left-attr",
341 .type = OPTIONS_TABLE_ATTRIBUTES,
342 .default_num = 0
345 { .name = "status-left-bg",
346 .type = OPTIONS_TABLE_COLOUR,
347 .default_num = 8
350 { .name = "status-left-fg",
351 .type = OPTIONS_TABLE_COLOUR,
352 .default_num = 8
355 { .name = "status-left-length",
356 .type = OPTIONS_TABLE_NUMBER,
357 .minimum = 0,
358 .maximum = SHRT_MAX,
359 .default_num = 10
362 { .name = "status-right",
363 .type = OPTIONS_TABLE_STRING,
364 .default_str = "\"#22T\" %H:%M %d-%b-%y"
367 { .name = "status-right-attr",
368 .type = OPTIONS_TABLE_ATTRIBUTES,
369 .default_num = 0
372 { .name = "status-right-bg",
373 .type = OPTIONS_TABLE_COLOUR,
374 .default_num = 8
377 { .name = "status-right-fg",
378 .type = OPTIONS_TABLE_COLOUR,
379 .default_num = 8
382 { .name = "status-right-length",
383 .type = OPTIONS_TABLE_NUMBER,
384 .minimum = 0,
385 .maximum = SHRT_MAX,
386 .default_num = 40
389 { .name = "status-utf8",
390 .type = OPTIONS_TABLE_FLAG,
391 .default_num = 0 /* overridden in main() */
394 { .name = "terminal-overrides",
395 .type = OPTIONS_TABLE_STRING,
396 .default_str = "*88col*:colors=88,*256col*:colors=256"
397 ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
398 ":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
399 ":Cs=\\E[%p1%d q:Csr=\\E[2 q,screen*:XT"
402 { .name = "update-environment",
403 .type = OPTIONS_TABLE_STRING,
404 .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
405 "SSH_CONNECTION WINDOWID XAUTHORITY"
409 { .name = "visual-activity",
410 .type = OPTIONS_TABLE_FLAG,
411 .default_num = 0
414 { .name = "visual-bell",
415 .type = OPTIONS_TABLE_FLAG,
416 .default_num = 0
419 { .name = "visual-content",
420 .type = OPTIONS_TABLE_FLAG,
421 .default_num = 0
424 { .name = "visual-silence",
425 .type = OPTIONS_TABLE_FLAG,
426 .default_num = 0
429 { .name = "word-separators",
430 .type = OPTIONS_TABLE_STRING,
431 .default_str = " -_@"
434 { .name = NULL }
437 /* Window options. */
438 const struct options_table_entry window_options_table[] = {
439 { .name = "aggressive-resize",
440 .type = OPTIONS_TABLE_FLAG,
441 .default_num = 0
444 { .name = "allow-rename",
445 .type = OPTIONS_TABLE_FLAG,
446 .default_num = 1
449 { .name = "alternate-screen",
450 .type = OPTIONS_TABLE_FLAG,
451 .default_num = 1
454 { .name = "automatic-rename",
455 .type = OPTIONS_TABLE_FLAG,
456 .default_num = 1
459 { .name = "clock-mode-colour",
460 .type = OPTIONS_TABLE_COLOUR,
461 .default_num = 4
464 { .name = "clock-mode-style",
465 .type = OPTIONS_TABLE_CHOICE,
466 .choices = options_table_clock_mode_style_list,
467 .default_num = 1
470 { .name = "force-height",
471 .type = OPTIONS_TABLE_NUMBER,
472 .minimum = 0,
473 .maximum = INT_MAX,
474 .default_num = 0
477 { .name = "force-width",
478 .type = OPTIONS_TABLE_NUMBER,
479 .minimum = 0,
480 .maximum = INT_MAX,
481 .default_num = 0
484 { .name = "main-pane-height",
485 .type = OPTIONS_TABLE_NUMBER,
486 .minimum = 1,
487 .maximum = INT_MAX,
488 .default_num = 24
491 { .name = "main-pane-width",
492 .type = OPTIONS_TABLE_NUMBER,
493 .minimum = 1,
494 .maximum = INT_MAX,
495 .default_num = 80
498 { .name = "mode-attr",
499 .type = OPTIONS_TABLE_ATTRIBUTES,
500 .default_num = 0
503 { .name = "mode-bg",
504 .type = OPTIONS_TABLE_COLOUR,
505 .default_num = 3
508 { .name = "mode-fg",
509 .type = OPTIONS_TABLE_COLOUR,
510 .default_num = 0
513 { .name = "mode-keys",
514 .type = OPTIONS_TABLE_CHOICE,
515 .choices = options_table_mode_keys_list,
516 .default_num = MODEKEY_EMACS
519 { .name = "mode-mouse",
520 .type = OPTIONS_TABLE_CHOICE,
521 .choices = options_table_mode_mouse_list,
522 .default_num = 0
525 { .name = "monitor-activity",
526 .type = OPTIONS_TABLE_FLAG,
527 .default_num = 0
530 { .name = "monitor-content",
531 .type = OPTIONS_TABLE_STRING,
532 .default_str = ""
535 { .name = "monitor-silence",
536 .type = OPTIONS_TABLE_NUMBER,
537 .minimum = 0,
538 .maximum = INT_MAX,
539 .default_num = 0
542 { .name = "other-pane-height",
543 .type = OPTIONS_TABLE_NUMBER,
544 .minimum = 0,
545 .maximum = INT_MAX,
546 .default_num = 0
549 { .name = "other-pane-width",
550 .type = OPTIONS_TABLE_NUMBER,
551 .minimum = 0,
552 .maximum = INT_MAX,
553 .default_num = 0
556 { .name = "pane-base-index",
557 .type = OPTIONS_TABLE_NUMBER,
558 .minimum = 0,
559 .maximum = USHRT_MAX,
560 .default_num = 0
563 { .name = "remain-on-exit",
564 .type = OPTIONS_TABLE_FLAG,
565 .default_num = 0
568 { .name = "synchronize-panes",
569 .type = OPTIONS_TABLE_FLAG,
570 .default_num = 0
573 { .name = "utf8",
574 .type = OPTIONS_TABLE_FLAG,
575 .default_num = 0 /* overridden in main() */
578 { .name = "window-status-bell-attr",
579 .type = OPTIONS_TABLE_ATTRIBUTES,
580 .default_num = GRID_ATTR_REVERSE
583 { .name = "window-status-bell-bg",
584 .type = OPTIONS_TABLE_COLOUR,
585 .default_num = 8
588 { .name = "window-status-bell-fg",
589 .type = OPTIONS_TABLE_COLOUR,
590 .default_num = 8
593 { .name = "window-status-content-attr",
594 .type = OPTIONS_TABLE_ATTRIBUTES,
595 .default_num = GRID_ATTR_REVERSE
598 { .name = "window-status-content-bg",
599 .type = OPTIONS_TABLE_COLOUR,
600 .default_num = 8
603 { .name = "window-status-content-fg",
604 .type = OPTIONS_TABLE_COLOUR,
605 .default_num = 8
608 { .name = "window-status-activity-attr",
609 .type = OPTIONS_TABLE_ATTRIBUTES,
610 .default_num = GRID_ATTR_REVERSE
613 { .name = "window-status-activity-bg",
614 .type = OPTIONS_TABLE_COLOUR,
615 .default_num = 8
618 { .name = "window-status-activity-fg",
619 .type = OPTIONS_TABLE_COLOUR,
620 .default_num = 8
623 { .name = "window-status-attr",
624 .type = OPTIONS_TABLE_ATTRIBUTES,
625 .default_num = 0
628 { .name = "window-status-bg",
629 .type = OPTIONS_TABLE_COLOUR,
630 .default_num = 8
633 { .name = "window-status-current-attr",
634 .type = OPTIONS_TABLE_ATTRIBUTES,
635 .default_num = 0
638 { .name = "window-status-current-bg",
639 .type = OPTIONS_TABLE_COLOUR,
640 .default_num = 8
643 { .name = "window-status-current-fg",
644 .type = OPTIONS_TABLE_COLOUR,
645 .default_num = 8
648 { .name = "window-status-current-format",
649 .type = OPTIONS_TABLE_STRING,
650 .default_str = "#I:#W#F"
653 { .name = "window-status-fg",
654 .type = OPTIONS_TABLE_COLOUR,
655 .default_num = 8
658 { .name = "window-status-format",
659 .type = OPTIONS_TABLE_STRING,
660 .default_str = "#I:#W#F"
663 { .name = "xterm-keys",
664 .type = OPTIONS_TABLE_FLAG,
665 .default_num = 0
668 { .name = NULL }
671 /* Populate an options tree from a table. */
672 void
673 options_table_populate_tree(
674 const struct options_table_entry *table, struct options *oo)
676 const struct options_table_entry *oe;
678 for (oe = table; oe->name != NULL; oe++) {
679 if (oe->default_str != NULL)
680 options_set_string(oo, oe->name, "%s", oe->default_str);
681 else
682 options_set_number(oo, oe->name, oe->default_num);
686 /* Print an option using its type from the table. */
687 const char *
688 options_table_print_entry(
689 const struct options_table_entry *oe, struct options_entry *o)
691 static char out[BUFSIZ];
692 const char *s;
694 *out = '\0';
695 switch (oe->type) {
696 case OPTIONS_TABLE_STRING:
697 xsnprintf(out, sizeof out, "\"%s\"", o->str);
698 break;
699 case OPTIONS_TABLE_NUMBER:
700 xsnprintf(out, sizeof out, "%lld", o->num);
701 break;
702 case OPTIONS_TABLE_KEY:
703 xsnprintf(out, sizeof out, "%s", key_string_lookup_key(o->num));
704 break;
705 case OPTIONS_TABLE_COLOUR:
706 s = colour_tostring(o->num);
707 xsnprintf(out, sizeof out, "%s", s);
708 break;
709 case OPTIONS_TABLE_ATTRIBUTES:
710 s = attributes_tostring(o->num);
711 xsnprintf(out, sizeof out, "%s", s);
712 break;
713 case OPTIONS_TABLE_FLAG:
714 if (o->num)
715 strlcpy(out, "on", sizeof out);
716 else
717 strlcpy(out, "off", sizeof out);
718 break;
719 case OPTIONS_TABLE_CHOICE:
720 s = oe->choices[o->num];
721 xsnprintf(out, sizeof out, "%s", s);
722 break;
724 return (out);