Annotation of src/usr.bin/tmux/options-table.c, Revision 1.9
1.9 ! nicm 1: /* $OpenBSD: options-table.c,v 1.8 2011/05/18 20:24:29 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.1 nicm 371: },
372:
373: { .name = "update-environment",
374: .type = OPTIONS_TABLE_STRING,
375: .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
1.9 ! nicm 376: "SSH_CONNECTION WINDOWID XAUTHORITY"
1.1 nicm 377:
378: },
379:
380: { .name = "visual-activity",
381: .type = OPTIONS_TABLE_FLAG,
382: .default_num = 0
383: },
384:
385: { .name = "visual-bell",
386: .type = OPTIONS_TABLE_FLAG,
387: .default_num = 0
388: },
389:
390: { .name = "visual-content",
391: .type = OPTIONS_TABLE_FLAG,
392: .default_num = 0
393: },
394:
395: { .name = "visual-silence",
396: .type = OPTIONS_TABLE_FLAG,
397: .default_num = 0
398: },
399:
400: { .name = NULL }
401: };
402:
403: /* Window options. */
404: const struct options_table_entry window_options_table[] = {
405: { .name = "aggressive-resize",
406: .type = OPTIONS_TABLE_FLAG,
407: .default_num = 0
408: },
409:
410: { .name = "alternate-screen",
411: .type = OPTIONS_TABLE_FLAG,
412: .default_num = 1
413: },
414:
415: { .name = "automatic-rename",
416: .type = OPTIONS_TABLE_FLAG,
417: .default_num = 1
418: },
419:
420: { .name = "clock-mode-colour",
421: .type = OPTIONS_TABLE_COLOUR,
422: .default_num = 4
423: },
424:
425: { .name = "clock-mode-style",
426: .type = OPTIONS_TABLE_CHOICE,
427: .choices = options_table_clock_mode_style_list,
428: .default_num = 1
429: },
430:
431: { .name = "force-height",
432: .type = OPTIONS_TABLE_NUMBER,
433: .minimum = 0,
434: .maximum = INT_MAX,
435: .default_num = 0
436: },
437:
438: { .name = "force-width",
439: .type = OPTIONS_TABLE_NUMBER,
440: .minimum = 0,
441: .maximum = INT_MAX,
442: .default_num = 0
443: },
444:
445: { .name = "main-pane-height",
446: .type = OPTIONS_TABLE_NUMBER,
447: .minimum = 1,
448: .maximum = INT_MAX,
449: .default_num = 24
450: },
451:
452: { .name = "main-pane-width",
453: .type = OPTIONS_TABLE_NUMBER,
454: .minimum = 1,
455: .maximum = INT_MAX,
456: .default_num = 80
457: },
458:
459: { .name = "mode-attr",
460: .type = OPTIONS_TABLE_ATTRIBUTES,
461: .default_num = 0
462: },
463:
464: { .name = "mode-bg",
465: .type = OPTIONS_TABLE_COLOUR,
466: .default_num = 3
467: },
468:
469: { .name = "mode-fg",
470: .type = OPTIONS_TABLE_COLOUR,
471: .default_num = 0
472: },
473:
474: { .name = "mode-keys",
475: .type = OPTIONS_TABLE_CHOICE,
476: .choices = options_table_mode_keys_list,
477: .default_num = MODEKEY_EMACS
478: },
479:
480: { .name = "mode-mouse",
481: .type = OPTIONS_TABLE_FLAG,
482: .default_num = 0
483: },
484:
485: { .name = "monitor-activity",
486: .type = OPTIONS_TABLE_FLAG,
487: .default_num = 0
488: },
489:
490: { .name = "monitor-content",
491: .type = OPTIONS_TABLE_STRING,
492: .default_str = ""
493: },
494:
495: { .name = "monitor-silence",
496: .type = OPTIONS_TABLE_NUMBER,
497: .minimum = 0,
498: .maximum = INT_MAX,
499: .default_num = 0
500: },
501:
502: { .name = "other-pane-height",
503: .type = OPTIONS_TABLE_NUMBER,
504: .minimum = 0,
505: .maximum = INT_MAX,
506: .default_num = 0
507: },
508:
509: { .name = "other-pane-width",
510: .type = OPTIONS_TABLE_NUMBER,
511: .minimum = 0,
512: .maximum = INT_MAX,
513: .default_num = 0
514: },
515:
516: { .name = "remain-on-exit",
517: .type = OPTIONS_TABLE_FLAG,
518: .default_num = 0
519: },
520:
521: { .name = "synchronize-panes",
522: .type = OPTIONS_TABLE_FLAG,
523: .default_num = 0
524: },
525:
526: { .name = "utf8",
527: .type = OPTIONS_TABLE_FLAG,
528: .default_num = 0 /* overridden in main() */
529: },
530:
531: { .name = "window-status-alert-attr",
532: .type = OPTIONS_TABLE_ATTRIBUTES,
533: .default_num = GRID_ATTR_REVERSE
534: },
535:
536: { .name = "window-status-alert-bg",
537: .type = OPTIONS_TABLE_COLOUR,
538: .default_num = 8
539: },
540:
541: { .name = "window-status-alert-fg",
542: .type = OPTIONS_TABLE_COLOUR,
543: .default_num = 8
544: },
545:
546: { .name = "window-status-attr",
547: .type = OPTIONS_TABLE_ATTRIBUTES,
548: .default_num = 0
549: },
550:
551: { .name = "window-status-bg",
552: .type = OPTIONS_TABLE_COLOUR,
553: .default_num = 8
554: },
555:
556: { .name = "window-status-current-attr",
557: .type = OPTIONS_TABLE_ATTRIBUTES,
558: .default_num = 0
559: },
560:
561: { .name = "window-status-current-bg",
562: .type = OPTIONS_TABLE_COLOUR,
563: .default_num = 8
564: },
565:
566: { .name = "window-status-current-fg",
567: .type = OPTIONS_TABLE_COLOUR,
568: .default_num = 8
569: },
570:
571: { .name = "window-status-current-format",
572: .type = OPTIONS_TABLE_STRING,
573: .default_str = "#I:#W#F"
574: },
575:
576: { .name = "window-status-fg",
577: .type = OPTIONS_TABLE_COLOUR,
578: .default_num = 8
579: },
580:
581: { .name = "window-status-format",
582: .type = OPTIONS_TABLE_STRING,
583: .default_str = "#I:#W#F"
584: },
585:
586: { .name = "word-separators",
587: .type = OPTIONS_TABLE_STRING,
588: .default_str = " -_@"
589: },
590:
591: { .name = "xterm-keys",
592: .type = OPTIONS_TABLE_FLAG,
593: .default_num = 0
594: },
595:
596: { .name = NULL }
597: };
598:
599: /* Populate an options tree from a table. */
600: void
601: options_table_populate_tree(
602: const struct options_table_entry *table, struct options *oo)
603: {
604: const struct options_table_entry *oe;
605:
606: for (oe = table; oe->name != NULL; oe++) {
607: if (oe->default_str != NULL)
608: options_set_string(oo, oe->name, "%s", oe->default_str);
609: else
610: options_set_number(oo, oe->name, oe->default_num);
611: }
612: }
613:
614: /* Print an option using its type from the table. */
615: const char *
616: options_table_print_entry(
617: const struct options_table_entry *oe, struct options_entry *o)
618: {
619: static char out[BUFSIZ];
620: const char *s;
621: struct keylist *keylist;
622: u_int i;
623:
624: *out = '\0';
625: switch (oe->type) {
626: case OPTIONS_TABLE_STRING:
627: xsnprintf(out, sizeof out, "\"%s\"", o->str);
628: break;
629: case OPTIONS_TABLE_NUMBER:
630: xsnprintf(out, sizeof out, "%lld", o->num);
631: break;
632: case OPTIONS_TABLE_KEYS:
633: keylist = o->data;
634: for (i = 0; i < ARRAY_LENGTH(keylist); i++) {
635: s = key_string_lookup_key(ARRAY_ITEM(keylist, i));
636: strlcat(out, s, sizeof out);
637: if (i != ARRAY_LENGTH(keylist) - 1)
638: strlcat(out, ",", sizeof out);
639: }
640: break;
641: case OPTIONS_TABLE_COLOUR:
642: s = colour_tostring(o->num);
643: xsnprintf(out, sizeof out, "%s", s);
644: break;
645: case OPTIONS_TABLE_ATTRIBUTES:
646: s = attributes_tostring(o->num);
647: xsnprintf(out, sizeof out, "%s", s);
648: break;
649: case OPTIONS_TABLE_FLAG:
650: if (o->num)
651: strlcpy(out, "on", sizeof out);
652: else
653: strlcpy(out, "off", sizeof out);
654: break;
655: case OPTIONS_TABLE_CHOICE:
656: s = oe->choices[o->num];
657: xsnprintf(out, sizeof out, "%s", s);
658: break;
659: }
660: return (out);
661: }