Annotation of src/usr.bin/tmux/options-table.c, Revision 1.10
1.10 ! nicm 1: /* $OpenBSD: options-table.c,v 1.9 2011/05/20 19:03:58 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
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.
9: *
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.
17: */
18:
19: #include <sys/types.h>
20:
21: #include <string.h>
22: #include <paths.h>
23:
24: #include "tmux.h"
25:
26: /*
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.
33: */
34:
35: /* Choice option type lists. */
36: const char *options_table_mode_keys_list[] = {
37: "emacs", "vi", NULL
38: };
39: const char *options_table_clock_mode_style_list[] = {
40: "12", "24", NULL
41: };
42: const char *options_table_status_keys_list[] = {
43: "emacs", "vi", NULL
44: };
45: const char *options_table_status_justify_list[] = {
46: "left", "centre", "right", NULL
47: };
48: const char *options_table_bell_action_list[] = {
49: "none", "any", "current", NULL
50: };
51:
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,
1.4 nicm 58: .default_num = 20
1.1 nicm 59: },
60:
61: { .name = "escape-time",
62: .type = OPTIONS_TABLE_NUMBER,
63: .minimum = 0,
64: .maximum = INT_MAX,
65: .default_num = 500
66: },
67:
68: { .name = "exit-unattached",
69: .type = OPTIONS_TABLE_FLAG,
70: .default_num = 0
71: },
72:
73: { .name = "quiet",
74: .type = OPTIONS_TABLE_FLAG,
75: .default_num = 0 /* overridden in main() */
76: },
77:
1.8 nicm 78: { .name = "set-clipboard",
79: .type = OPTIONS_TABLE_FLAG,
80: .default_num = 1
81: },
82:
1.1 nicm 83: { .name = NULL }
84: };
85:
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
93: },
94:
95: { .name = "bell-action",
96: .type = OPTIONS_TABLE_CHOICE,
97: .choices = options_table_bell_action_list,
98: .default_num = BELL_ANY
99: },
100:
101: { .name = "default-command",
102: .type = OPTIONS_TABLE_STRING,
103: .default_str = ""
104: },
105:
106: { .name = "default-path",
107: .type = OPTIONS_TABLE_STRING,
108: .default_str = ""
109: },
110:
111: { .name = "default-shell",
112: .type = OPTIONS_TABLE_STRING,
113: .default_str = _PATH_BSHELL
114: },
115:
116: { .name = "default-terminal",
117: .type = OPTIONS_TABLE_STRING,
118: .default_str = "screen"
119: },
120:
121: { .name = "destroy-unattached",
122: .type = OPTIONS_TABLE_FLAG,
123: .default_num = 0
124: },
125:
126: { .name = "detach-on-destroy",
127: .type = OPTIONS_TABLE_FLAG,
128: .default_num = 1
129: },
130:
131: { .name = "display-panes-active-colour",
132: .type = OPTIONS_TABLE_COLOUR,
133: .default_num = 1
134: },
135:
136: { .name = "display-panes-colour",
137: .type = OPTIONS_TABLE_COLOUR,
138: .default_num = 4
139: },
140:
141: { .name = "display-panes-time",
142: .type = OPTIONS_TABLE_NUMBER,
143: .minimum = 1,
144: .maximum = INT_MAX,
145: .default_num = 1000
146: },
147:
148: { .name = "display-time",
149: .type = OPTIONS_TABLE_NUMBER,
150: .minimum = 1,
151: .maximum = INT_MAX,
152: .default_num = 750
153: },
154:
155: { .name = "history-limit",
156: .type = OPTIONS_TABLE_NUMBER,
157: .minimum = 0,
1.3 nicm 158: .maximum = INT_MAX,
1.1 nicm 159: .default_num = 2000
160: },
161:
162: { .name = "lock-after-time",
163: .type = OPTIONS_TABLE_NUMBER,
164: .minimum = 0,
165: .maximum = INT_MAX,
166: .default_num = 0
167: },
168:
169: { .name = "lock-command",
170: .type = OPTIONS_TABLE_STRING,
171: .default_str = "lock -np"
172: },
173:
174: { .name = "lock-server",
175: .type = OPTIONS_TABLE_FLAG,
176: .default_num = 1
177: },
178:
179: { .name = "message-attr",
180: .type = OPTIONS_TABLE_ATTRIBUTES,
181: .default_num = 0
182: },
183:
184: { .name = "message-bg",
185: .type = OPTIONS_TABLE_COLOUR,
186: .default_num = 3
187: },
188:
189: { .name = "message-fg",
190: .type = OPTIONS_TABLE_COLOUR,
191: .default_num = 0
192: },
193:
194: { .name = "message-limit",
195: .type = OPTIONS_TABLE_NUMBER,
196: .minimum = 0,
197: .maximum = INT_MAX,
198: .default_num = 20
1.7 nicm 199: },
200:
201: { .name = "mouse-resize-pane",
202: .type = OPTIONS_TABLE_FLAG,
203: .default_num = 0
1.1 nicm 204: },
205:
206: { .name = "mouse-select-pane",
1.5 nicm 207: .type = OPTIONS_TABLE_FLAG,
208: .default_num = 0
209: },
210:
211: { .name = "mouse-select-window",
1.2 nicm 212: .type = OPTIONS_TABLE_FLAG,
213: .default_num = 0
214: },
215:
216: { .name = "mouse-utf8",
1.1 nicm 217: .type = OPTIONS_TABLE_FLAG,
218: .default_num = 0
219: },
220:
221: { .name = "pane-active-border-bg",
222: .type = OPTIONS_TABLE_COLOUR,
223: .default_num = 8
224: },
225:
226: { .name = "pane-active-border-fg",
227: .type = OPTIONS_TABLE_COLOUR,
228: .default_num = 2
229: },
230:
231: { .name = "pane-border-bg",
232: .type = OPTIONS_TABLE_COLOUR,
233: .default_num = 8
234: },
235:
236: { .name = "pane-border-fg",
237: .type = OPTIONS_TABLE_COLOUR,
238: .default_num = 8
239: },
240:
241: { .name = "prefix",
242: .type = OPTIONS_TABLE_KEYS,
243: /* set in main() */
244: },
245:
246: { .name = "repeat-time",
247: .type = OPTIONS_TABLE_NUMBER,
248: .minimum = 0,
249: .maximum = SHRT_MAX,
250: .default_num = 500
251: },
252:
253: { .name = "set-remain-on-exit",
254: .type = OPTIONS_TABLE_FLAG,
255: .default_num = 0
256: },
257:
258: { .name = "set-titles",
259: .type = OPTIONS_TABLE_FLAG,
260: .default_num = 0
261: },
262:
263: { .name = "set-titles-string",
264: .type = OPTIONS_TABLE_STRING,
265: .default_str = "#S:#I:#W - \"#T\""
266: },
267:
268: { .name = "status",
269: .type = OPTIONS_TABLE_FLAG,
270: .default_num = 1
271: },
272:
273: { .name = "status-attr",
274: .type = OPTIONS_TABLE_ATTRIBUTES,
275: .default_num = 0
276: },
277:
278: { .name = "status-bg",
279: .type = OPTIONS_TABLE_COLOUR,
280: .default_num = 2
281: },
282:
283: { .name = "status-fg",
284: .type = OPTIONS_TABLE_COLOUR,
285: .default_num = 0
286: },
287:
288: { .name = "status-interval",
289: .type = OPTIONS_TABLE_NUMBER,
290: .minimum = 0,
291: .maximum = INT_MAX,
292: .default_num = 15
293: },
294:
295: { .name = "status-justify",
296: .type = OPTIONS_TABLE_CHOICE,
297: .choices = options_table_status_justify_list,
298: .default_num = 0
299: },
300:
301: { .name = "status-keys",
302: .type = OPTIONS_TABLE_CHOICE,
303: .choices = options_table_status_keys_list,
304: .default_num = MODEKEY_EMACS
305: },
306:
307: { .name = "status-left",
308: .type = OPTIONS_TABLE_STRING,
309: .default_str = "[#S]"
310: },
311:
312: { .name = "status-left-attr",
313: .type = OPTIONS_TABLE_ATTRIBUTES,
314: .default_num = 0
315: },
316:
317: { .name = "status-left-bg",
318: .type = OPTIONS_TABLE_COLOUR,
319: .default_num = 8
320: },
321:
322: { .name = "status-left-fg",
323: .type = OPTIONS_TABLE_COLOUR,
324: .default_num = 8
325: },
326:
327: { .name = "status-left-length",
328: .type = OPTIONS_TABLE_NUMBER,
329: .minimum = 0,
330: .maximum = SHRT_MAX,
331: .default_num = 10
332: },
333:
334: { .name = "status-right",
335: .type = OPTIONS_TABLE_STRING,
336: .default_str = "\"#22T\" %H:%M %d-%b-%y"
337: },
338:
339: { .name = "status-right-attr",
340: .type = OPTIONS_TABLE_ATTRIBUTES,
341: .default_num = 0
342: },
343:
344: { .name = "status-right-bg",
345: .type = OPTIONS_TABLE_COLOUR,
346: .default_num = 8
347: },
348:
349: { .name = "status-right-fg",
350: .type = OPTIONS_TABLE_COLOUR,
351: .default_num = 8
352: },
353:
354: { .name = "status-right-length",
355: .type = OPTIONS_TABLE_NUMBER,
356: .minimum = 0,
357: .maximum = SHRT_MAX,
358: .default_num = 40
359: },
360:
361: { .name = "status-utf8",
362: .type = OPTIONS_TABLE_FLAG,
363: .default_num = 0 /* overridden in main() */
364: },
365:
366: { .name = "terminal-overrides",
367: .type = OPTIONS_TABLE_STRING,
1.8 nicm 368: .default_str = "*88col*:colors=88,*256col*:colors=256"
1.9 nicm 369: ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
370: ":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
1.10 ! nicm 371: ":Cs=\\E[%p1%d q:Csr=\\E[2 q"
1.1 nicm 372: },
373:
374: { .name = "update-environment",
375: .type = OPTIONS_TABLE_STRING,
376: .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
1.9 nicm 377: "SSH_CONNECTION WINDOWID XAUTHORITY"
1.1 nicm 378:
379: },
380:
381: { .name = "visual-activity",
382: .type = OPTIONS_TABLE_FLAG,
383: .default_num = 0
384: },
385:
386: { .name = "visual-bell",
387: .type = OPTIONS_TABLE_FLAG,
388: .default_num = 0
389: },
390:
391: { .name = "visual-content",
392: .type = OPTIONS_TABLE_FLAG,
393: .default_num = 0
394: },
395:
396: { .name = "visual-silence",
397: .type = OPTIONS_TABLE_FLAG,
398: .default_num = 0
399: },
400:
401: { .name = NULL }
402: };
403:
404: /* Window options. */
405: const struct options_table_entry window_options_table[] = {
406: { .name = "aggressive-resize",
407: .type = OPTIONS_TABLE_FLAG,
408: .default_num = 0
409: },
410:
411: { .name = "alternate-screen",
412: .type = OPTIONS_TABLE_FLAG,
413: .default_num = 1
414: },
415:
416: { .name = "automatic-rename",
417: .type = OPTIONS_TABLE_FLAG,
418: .default_num = 1
419: },
420:
421: { .name = "clock-mode-colour",
422: .type = OPTIONS_TABLE_COLOUR,
423: .default_num = 4
424: },
425:
426: { .name = "clock-mode-style",
427: .type = OPTIONS_TABLE_CHOICE,
428: .choices = options_table_clock_mode_style_list,
429: .default_num = 1
430: },
431:
432: { .name = "force-height",
433: .type = OPTIONS_TABLE_NUMBER,
434: .minimum = 0,
435: .maximum = INT_MAX,
436: .default_num = 0
437: },
438:
439: { .name = "force-width",
440: .type = OPTIONS_TABLE_NUMBER,
441: .minimum = 0,
442: .maximum = INT_MAX,
443: .default_num = 0
444: },
445:
446: { .name = "main-pane-height",
447: .type = OPTIONS_TABLE_NUMBER,
448: .minimum = 1,
449: .maximum = INT_MAX,
450: .default_num = 24
451: },
452:
453: { .name = "main-pane-width",
454: .type = OPTIONS_TABLE_NUMBER,
455: .minimum = 1,
456: .maximum = INT_MAX,
457: .default_num = 80
458: },
459:
460: { .name = "mode-attr",
461: .type = OPTIONS_TABLE_ATTRIBUTES,
462: .default_num = 0
463: },
464:
465: { .name = "mode-bg",
466: .type = OPTIONS_TABLE_COLOUR,
467: .default_num = 3
468: },
469:
470: { .name = "mode-fg",
471: .type = OPTIONS_TABLE_COLOUR,
472: .default_num = 0
473: },
474:
475: { .name = "mode-keys",
476: .type = OPTIONS_TABLE_CHOICE,
477: .choices = options_table_mode_keys_list,
478: .default_num = MODEKEY_EMACS
479: },
480:
481: { .name = "mode-mouse",
482: .type = OPTIONS_TABLE_FLAG,
483: .default_num = 0
484: },
485:
486: { .name = "monitor-activity",
487: .type = OPTIONS_TABLE_FLAG,
488: .default_num = 0
489: },
490:
491: { .name = "monitor-content",
492: .type = OPTIONS_TABLE_STRING,
493: .default_str = ""
494: },
495:
496: { .name = "monitor-silence",
497: .type = OPTIONS_TABLE_NUMBER,
498: .minimum = 0,
499: .maximum = INT_MAX,
500: .default_num = 0
501: },
502:
503: { .name = "other-pane-height",
504: .type = OPTIONS_TABLE_NUMBER,
505: .minimum = 0,
506: .maximum = INT_MAX,
507: .default_num = 0
508: },
509:
510: { .name = "other-pane-width",
511: .type = OPTIONS_TABLE_NUMBER,
512: .minimum = 0,
513: .maximum = INT_MAX,
514: .default_num = 0
515: },
516:
517: { .name = "remain-on-exit",
518: .type = OPTIONS_TABLE_FLAG,
519: .default_num = 0
520: },
521:
522: { .name = "synchronize-panes",
523: .type = OPTIONS_TABLE_FLAG,
524: .default_num = 0
525: },
526:
527: { .name = "utf8",
528: .type = OPTIONS_TABLE_FLAG,
529: .default_num = 0 /* overridden in main() */
530: },
531:
532: { .name = "window-status-alert-attr",
533: .type = OPTIONS_TABLE_ATTRIBUTES,
534: .default_num = GRID_ATTR_REVERSE
535: },
536:
537: { .name = "window-status-alert-bg",
538: .type = OPTIONS_TABLE_COLOUR,
539: .default_num = 8
540: },
541:
542: { .name = "window-status-alert-fg",
543: .type = OPTIONS_TABLE_COLOUR,
544: .default_num = 8
545: },
546:
547: { .name = "window-status-attr",
548: .type = OPTIONS_TABLE_ATTRIBUTES,
549: .default_num = 0
550: },
551:
552: { .name = "window-status-bg",
553: .type = OPTIONS_TABLE_COLOUR,
554: .default_num = 8
555: },
556:
557: { .name = "window-status-current-attr",
558: .type = OPTIONS_TABLE_ATTRIBUTES,
559: .default_num = 0
560: },
561:
562: { .name = "window-status-current-bg",
563: .type = OPTIONS_TABLE_COLOUR,
564: .default_num = 8
565: },
566:
567: { .name = "window-status-current-fg",
568: .type = OPTIONS_TABLE_COLOUR,
569: .default_num = 8
570: },
571:
572: { .name = "window-status-current-format",
573: .type = OPTIONS_TABLE_STRING,
574: .default_str = "#I:#W#F"
575: },
576:
577: { .name = "window-status-fg",
578: .type = OPTIONS_TABLE_COLOUR,
579: .default_num = 8
580: },
581:
582: { .name = "window-status-format",
583: .type = OPTIONS_TABLE_STRING,
584: .default_str = "#I:#W#F"
585: },
586:
587: { .name = "word-separators",
588: .type = OPTIONS_TABLE_STRING,
589: .default_str = " -_@"
590: },
591:
592: { .name = "xterm-keys",
593: .type = OPTIONS_TABLE_FLAG,
594: .default_num = 0
595: },
596:
597: { .name = NULL }
598: };
599:
600: /* Populate an options tree from a table. */
601: void
602: options_table_populate_tree(
603: const struct options_table_entry *table, struct options *oo)
604: {
605: const struct options_table_entry *oe;
606:
607: for (oe = table; oe->name != NULL; oe++) {
608: if (oe->default_str != NULL)
609: options_set_string(oo, oe->name, "%s", oe->default_str);
610: else
611: options_set_number(oo, oe->name, oe->default_num);
612: }
613: }
614:
615: /* Print an option using its type from the table. */
616: const char *
617: options_table_print_entry(
618: const struct options_table_entry *oe, struct options_entry *o)
619: {
620: static char out[BUFSIZ];
621: const char *s;
622: struct keylist *keylist;
623: u_int i;
624:
625: *out = '\0';
626: switch (oe->type) {
627: case OPTIONS_TABLE_STRING:
628: xsnprintf(out, sizeof out, "\"%s\"", o->str);
629: break;
630: case OPTIONS_TABLE_NUMBER:
631: xsnprintf(out, sizeof out, "%lld", o->num);
632: break;
633: case OPTIONS_TABLE_KEYS:
634: keylist = o->data;
635: for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
636: s = key_string_lookup_key(ARRAY_ITEM(keylist, i));
637: strlcat(out, s, sizeof out);
638: if (i != ARRAY_LENGTH(keylist) - 1)
639: strlcat(out, ",", sizeof out);
640: }
641: break;
642: case OPTIONS_TABLE_COLOUR:
643: s = colour_tostring(o->num);
644: xsnprintf(out, sizeof out, "%s", s);
645: break;
646: case OPTIONS_TABLE_ATTRIBUTES:
647: s = attributes_tostring(o->num);
648: xsnprintf(out, sizeof out, "%s", s);
649: break;
650: case OPTIONS_TABLE_FLAG:
651: if (o->num)
652: strlcpy(out, "on", sizeof out);
653: else
654: strlcpy(out, "off", sizeof out);
655: break;
656: case OPTIONS_TABLE_CHOICE:
657: s = oe->choices[o->num];
658: xsnprintf(out, sizeof out, "%s", s);
659: break;
660: }
661: return (out);
662: }