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