options-table.c revision 1.76
1/* $OpenBSD: options-table.c,v 1.76 2016/12/30 13:49:34 nicm Exp $ */
2
3/*
4 * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
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 look up the real type when the
32 * user sets an option or its value needs to be shown.
33 */
34
35/* Choice option type lists. */
36static const char *options_table_mode_keys_list[] = {
37	"emacs", "vi", NULL
38};
39static const char *options_table_clock_mode_style_list[] = {
40	"12", "24", NULL
41};
42static const char *options_table_status_keys_list[] = {
43	"emacs", "vi", NULL
44};
45static const char *options_table_status_justify_list[] = {
46	"left", "centre", "right", NULL
47};
48static const char *options_table_status_position_list[] = {
49	"top", "bottom", NULL
50};
51static const char *options_table_bell_action_list[] = {
52	"none", "any", "current", "other", NULL
53};
54static const char *options_table_pane_status_list[] = {
55	"off", "top", "bottom", NULL
56};
57
58/* Server options. */
59const struct options_table_entry options_table[] = {
60	{ .name = "buffer-limit",
61	  .type = OPTIONS_TABLE_NUMBER,
62	  .scope = OPTIONS_TABLE_SERVER,
63	  .minimum = 1,
64	  .maximum = INT_MAX,
65	  .default_num = 20
66	},
67
68	{ .name = "default-terminal",
69	  .type = OPTIONS_TABLE_STRING,
70	  .scope = OPTIONS_TABLE_SERVER,
71	  .default_str = "screen"
72	},
73
74	{ .name = "escape-time",
75	  .type = OPTIONS_TABLE_NUMBER,
76	  .scope = OPTIONS_TABLE_SERVER,
77	  .minimum = 0,
78	  .maximum = INT_MAX,
79	  .default_num = 500
80	},
81
82	{ .name = "exit-unattached",
83	  .type = OPTIONS_TABLE_FLAG,
84	  .scope = OPTIONS_TABLE_SERVER,
85	  .default_num = 0
86	},
87
88	{ .name = "focus-events",
89	  .type = OPTIONS_TABLE_FLAG,
90	  .scope = OPTIONS_TABLE_SERVER,
91	  .default_num = 0
92	},
93
94	{ .name = "history-file",
95	  .type = OPTIONS_TABLE_STRING,
96	  .scope = OPTIONS_TABLE_SERVER,
97	  .default_str = ""
98	},
99
100	{ .name = "message-limit",
101	  .type = OPTIONS_TABLE_NUMBER,
102	  .scope = OPTIONS_TABLE_SERVER,
103	  .minimum = 0,
104	  .maximum = INT_MAX,
105	  .default_num = 100
106	},
107
108	{ .name = "quiet",
109	  .type = OPTIONS_TABLE_FLAG,
110	  .scope = OPTIONS_TABLE_SERVER,
111	  .default_num = 0
112	},
113
114	{ .name = "set-clipboard",
115	  .type = OPTIONS_TABLE_FLAG,
116	  .scope = OPTIONS_TABLE_SERVER,
117	  .default_num = 1
118	},
119
120	{ .name = "terminal-overrides",
121	  .type = OPTIONS_TABLE_STRING,
122	  .scope = OPTIONS_TABLE_SERVER,
123	  .default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
124	                 ":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
125			 ":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT"
126	},
127
128	{ .name = "assume-paste-time",
129	  .type = OPTIONS_TABLE_NUMBER,
130	  .scope = OPTIONS_TABLE_SESSION,
131	  .minimum = 0,
132	  .maximum = INT_MAX,
133	  .default_num = 1,
134	},
135
136	{ .name = "base-index",
137	  .type = OPTIONS_TABLE_NUMBER,
138	  .scope = OPTIONS_TABLE_SESSION,
139	  .minimum = 0,
140	  .maximum = INT_MAX,
141	  .default_num = 0
142	},
143
144	{ .name = "bell-action",
145	  .type = OPTIONS_TABLE_CHOICE,
146	  .scope = OPTIONS_TABLE_SESSION,
147	  .choices = options_table_bell_action_list,
148	  .default_num = BELL_ANY
149	},
150
151	{ .name = "bell-on-alert",
152	  .type = OPTIONS_TABLE_FLAG,
153	  .scope = OPTIONS_TABLE_SESSION,
154	  .default_num = 0
155	},
156
157	{ .name = "default-command",
158	  .type = OPTIONS_TABLE_STRING,
159	  .scope = OPTIONS_TABLE_SESSION,
160	  .default_str = ""
161	},
162
163	{ .name = "default-shell",
164	  .type = OPTIONS_TABLE_STRING,
165	  .scope = OPTIONS_TABLE_SESSION,
166	  .default_str = _PATH_BSHELL
167	},
168
169	{ .name = "destroy-unattached",
170	  .type = OPTIONS_TABLE_FLAG,
171	  .scope = OPTIONS_TABLE_SESSION,
172	  .default_num = 0
173	},
174
175	{ .name = "detach-on-destroy",
176	  .type = OPTIONS_TABLE_FLAG,
177	  .scope = OPTIONS_TABLE_SESSION,
178	  .default_num = 1
179	},
180
181	{ .name = "display-panes-active-colour",
182	  .type = OPTIONS_TABLE_COLOUR,
183	  .scope = OPTIONS_TABLE_SESSION,
184	  .default_num = 1
185	},
186
187	{ .name = "display-panes-colour",
188	  .type = OPTIONS_TABLE_COLOUR,
189	  .scope = OPTIONS_TABLE_SESSION,
190	  .default_num = 4
191	},
192
193	{ .name = "display-panes-time",
194	  .type = OPTIONS_TABLE_NUMBER,
195	  .scope = OPTIONS_TABLE_SESSION,
196	  .minimum = 1,
197	  .maximum = INT_MAX,
198	  .default_num = 1000
199	},
200
201	{ .name = "display-time",
202	  .type = OPTIONS_TABLE_NUMBER,
203	  .scope = OPTIONS_TABLE_SESSION,
204	  .minimum = 0,
205	  .maximum = INT_MAX,
206	  .default_num = 750
207	},
208
209	{ .name = "history-limit",
210	  .type = OPTIONS_TABLE_NUMBER,
211	  .scope = OPTIONS_TABLE_SESSION,
212	  .minimum = 0,
213	  .maximum = INT_MAX,
214	  .default_num = 2000
215	},
216
217	{ .name = "key-table",
218	  .type = OPTIONS_TABLE_STRING,
219	  .scope = OPTIONS_TABLE_SESSION,
220	  .default_str = "root"
221	},
222
223	{ .name = "lock-after-time",
224	  .type = OPTIONS_TABLE_NUMBER,
225	  .scope = OPTIONS_TABLE_SESSION,
226	  .minimum = 0,
227	  .maximum = INT_MAX,
228	  .default_num = 0
229	},
230
231	{ .name = "lock-command",
232	  .type = OPTIONS_TABLE_STRING,
233	  .scope = OPTIONS_TABLE_SESSION,
234	  .default_str = "lock -np"
235	},
236
237	{ .name = "message-attr",
238	  .type = OPTIONS_TABLE_ATTRIBUTES,
239	  .scope = OPTIONS_TABLE_SESSION,
240	  .default_num = 0,
241	  .style = "message-style"
242	},
243
244	{ .name = "message-bg",
245	  .type = OPTIONS_TABLE_COLOUR,
246	  .scope = OPTIONS_TABLE_SESSION,
247	  .default_num = 3,
248	  .style = "message-style"
249	},
250
251	{ .name = "message-command-attr",
252	  .type = OPTIONS_TABLE_ATTRIBUTES,
253	  .scope = OPTIONS_TABLE_SESSION,
254	  .default_num = 0,
255	  .style = "message-command-style"
256	},
257
258	{ .name = "message-command-bg",
259	  .type = OPTIONS_TABLE_COLOUR,
260	  .scope = OPTIONS_TABLE_SESSION,
261	  .default_num = 0,
262	  .style = "message-command-style"
263	},
264
265	{ .name = "message-command-fg",
266	  .type = OPTIONS_TABLE_COLOUR,
267	  .scope = OPTIONS_TABLE_SESSION,
268	  .default_num = 3,
269	  .style = "message-command-style"
270	},
271
272	{ .name = "message-command-style",
273	  .type = OPTIONS_TABLE_STYLE,
274	  .scope = OPTIONS_TABLE_SESSION,
275	  .default_str = "bg=black,fg=yellow"
276	},
277
278	{ .name = "message-fg",
279	  .type = OPTIONS_TABLE_COLOUR,
280	  .scope = OPTIONS_TABLE_SESSION,
281	  .default_num = 0,
282	  .style = "message-style"
283	},
284
285	{ .name = "message-style",
286	  .type = OPTIONS_TABLE_STYLE,
287	  .scope = OPTIONS_TABLE_SESSION,
288	  .default_str = "bg=yellow,fg=black"
289	},
290
291	{ .name = "mouse",
292	  .type = OPTIONS_TABLE_FLAG,
293	  .scope = OPTIONS_TABLE_SESSION,
294	  .default_num = 0
295	},
296
297	{ .name = "prefix",
298	  .type = OPTIONS_TABLE_KEY,
299	  .scope = OPTIONS_TABLE_SESSION,
300	  .default_num = '\002',
301	},
302
303	{ .name = "prefix2",
304	  .type = OPTIONS_TABLE_KEY,
305	  .scope = OPTIONS_TABLE_SESSION,
306	  .default_num = KEYC_NONE,
307	},
308
309	{ .name = "renumber-windows",
310	  .type = OPTIONS_TABLE_FLAG,
311	  .scope = OPTIONS_TABLE_SESSION,
312	  .default_num = 0
313	},
314
315	{ .name = "repeat-time",
316	  .type = OPTIONS_TABLE_NUMBER,
317	  .scope = OPTIONS_TABLE_SESSION,
318	  .minimum = 0,
319	  .maximum = SHRT_MAX,
320	  .default_num = 500
321	},
322
323	{ .name = "set-titles",
324	  .type = OPTIONS_TABLE_FLAG,
325	  .scope = OPTIONS_TABLE_SESSION,
326	  .default_num = 0
327	},
328
329	{ .name = "set-titles-string",
330	  .type = OPTIONS_TABLE_STRING,
331	  .scope = OPTIONS_TABLE_SESSION,
332	  .default_str = "#S:#I:#W - \"#T\" #{session_alerts}"
333	},
334
335	{ .name = "status",
336	  .type = OPTIONS_TABLE_FLAG,
337	  .scope = OPTIONS_TABLE_SESSION,
338	  .default_num = 1
339	},
340
341	{ .name = "status-attr",
342	  .type = OPTIONS_TABLE_ATTRIBUTES,
343	  .scope = OPTIONS_TABLE_SESSION,
344	  .default_num = 0,
345	  .style = "status-style"
346	},
347
348	{ .name = "status-bg",
349	  .type = OPTIONS_TABLE_COLOUR,
350	  .scope = OPTIONS_TABLE_SESSION,
351	  .default_num = 2,
352	  .style = "status-style"
353	},
354
355	{ .name = "status-fg",
356	  .type = OPTIONS_TABLE_COLOUR,
357	  .scope = OPTIONS_TABLE_SESSION,
358	  .default_num = 0,
359	  .style = "status-style"
360	},
361
362	{ .name = "status-interval",
363	  .type = OPTIONS_TABLE_NUMBER,
364	  .scope = OPTIONS_TABLE_SESSION,
365	  .minimum = 0,
366	  .maximum = INT_MAX,
367	  .default_num = 15
368	},
369
370	{ .name = "status-justify",
371	  .type = OPTIONS_TABLE_CHOICE,
372	  .scope = OPTIONS_TABLE_SESSION,
373	  .choices = options_table_status_justify_list,
374	  .default_num = 0
375	},
376
377	{ .name = "status-keys",
378	  .type = OPTIONS_TABLE_CHOICE,
379	  .scope = OPTIONS_TABLE_SESSION,
380	  .choices = options_table_status_keys_list,
381	  .default_num = MODEKEY_EMACS
382	},
383
384	{ .name = "status-left",
385	  .type = OPTIONS_TABLE_STRING,
386	  .scope = OPTIONS_TABLE_SESSION,
387	  .default_str = "[#S] "
388	},
389
390	{ .name = "status-left-attr",
391	  .type = OPTIONS_TABLE_ATTRIBUTES,
392	  .scope = OPTIONS_TABLE_SESSION,
393	  .default_num = 0,
394	  .style = "status-left-style"
395	},
396
397	{ .name = "status-left-bg",
398	  .type = OPTIONS_TABLE_COLOUR,
399	  .scope = OPTIONS_TABLE_SESSION,
400	  .default_num = 8,
401	  .style = "status-left-style"
402	},
403
404	{ .name = "status-left-fg",
405	  .type = OPTIONS_TABLE_COLOUR,
406	  .scope = OPTIONS_TABLE_SESSION,
407	  .default_num = 8,
408	  .style = "status-left-style"
409	},
410
411	{ .name = "status-left-length",
412	  .type = OPTIONS_TABLE_NUMBER,
413	  .scope = OPTIONS_TABLE_SESSION,
414	  .minimum = 0,
415	  .maximum = SHRT_MAX,
416	  .default_num = 10
417	},
418
419	{ .name = "status-left-style",
420	  .type = OPTIONS_TABLE_STYLE,
421	  .scope = OPTIONS_TABLE_SESSION,
422	  .default_str = "default"
423	},
424
425	{ .name = "status-position",
426	  .type = OPTIONS_TABLE_CHOICE,
427	  .scope = OPTIONS_TABLE_SESSION,
428	  .choices = options_table_status_position_list,
429	  .default_num = 1
430	},
431
432	{ .name = "status-right",
433	  .type = OPTIONS_TABLE_STRING,
434	  .scope = OPTIONS_TABLE_SESSION,
435	  .default_str = " \"#{=21:pane_title}\" %H:%M %d-%b-%y"
436	},
437
438	{ .name = "status-right-attr",
439	  .type = OPTIONS_TABLE_ATTRIBUTES,
440	  .scope = OPTIONS_TABLE_SESSION,
441	  .default_num = 0,
442	  .style = "status-right-style"
443	},
444
445	{ .name = "status-right-bg",
446	  .type = OPTIONS_TABLE_COLOUR,
447	  .scope = OPTIONS_TABLE_SESSION,
448	  .default_num = 8,
449	  .style = "status-right-style"
450	},
451
452	{ .name = "status-right-fg",
453	  .type = OPTIONS_TABLE_COLOUR,
454	  .scope = OPTIONS_TABLE_SESSION,
455	  .default_num = 8,
456	  .style = "status-right-style"
457	},
458
459	{ .name = "status-right-length",
460	  .type = OPTIONS_TABLE_NUMBER,
461	  .scope = OPTIONS_TABLE_SESSION,
462	  .minimum = 0,
463	  .maximum = SHRT_MAX,
464	  .default_num = 40
465	},
466
467	{ .name = "status-right-style",
468	  .type = OPTIONS_TABLE_STYLE,
469	  .scope = OPTIONS_TABLE_SESSION,
470	  .default_str = "default"
471	},
472
473	{ .name = "status-style",
474	  .type = OPTIONS_TABLE_STYLE,
475	  .scope = OPTIONS_TABLE_SESSION,
476	  .default_str = "bg=green,fg=black"
477	},
478
479	{ .name = "update-environment",
480	  .type = OPTIONS_TABLE_STRING,
481	  .scope = OPTIONS_TABLE_SESSION,
482	  .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
483	                 "SSH_CONNECTION WINDOWID XAUTHORITY"
484
485	},
486
487	{ .name = "visual-activity",
488	  .type = OPTIONS_TABLE_FLAG,
489	  .scope = OPTIONS_TABLE_SESSION,
490	  .default_num = 0
491	},
492
493	{ .name = "visual-bell",
494	  .type = OPTIONS_TABLE_FLAG,
495	  .scope = OPTIONS_TABLE_SESSION,
496	  .default_num = 0
497	},
498
499	{ .name = "visual-silence",
500	  .type = OPTIONS_TABLE_FLAG,
501	  .scope = OPTIONS_TABLE_SESSION,
502	  .default_num = 0
503	},
504
505	{ .name = "word-separators",
506	  .type = OPTIONS_TABLE_STRING,
507	  .scope = OPTIONS_TABLE_SESSION,
508	  .default_str = " -_@"
509	},
510
511	{ .name = "aggressive-resize",
512	  .type = OPTIONS_TABLE_FLAG,
513	  .scope = OPTIONS_TABLE_WINDOW,
514	  .default_num = 0
515	},
516
517	{ .name = "allow-rename",
518	  .type = OPTIONS_TABLE_FLAG,
519	  .scope = OPTIONS_TABLE_WINDOW,
520	  .default_num = 1
521	},
522
523	{ .name = "alternate-screen",
524	  .type = OPTIONS_TABLE_FLAG,
525	  .scope = OPTIONS_TABLE_WINDOW,
526	  .default_num = 1
527	},
528
529	{ .name = "automatic-rename",
530	  .type = OPTIONS_TABLE_FLAG,
531	  .scope = OPTIONS_TABLE_WINDOW,
532	  .default_num = 1
533	},
534
535	{ .name = "automatic-rename-format",
536	  .type = OPTIONS_TABLE_STRING,
537	  .scope = OPTIONS_TABLE_WINDOW,
538	  .default_str = "#{?pane_in_mode,[tmux],#{pane_current_command}}"
539	                 "#{?pane_dead,[dead],}"
540	},
541
542	{ .name = "clock-mode-colour",
543	  .type = OPTIONS_TABLE_COLOUR,
544	  .scope = OPTIONS_TABLE_WINDOW,
545	  .default_num = 4
546	},
547
548	{ .name = "clock-mode-style",
549	  .type = OPTIONS_TABLE_CHOICE,
550	  .scope = OPTIONS_TABLE_WINDOW,
551	  .choices = options_table_clock_mode_style_list,
552	  .default_num = 1
553	},
554
555	{ .name = "force-height",
556	  .type = OPTIONS_TABLE_NUMBER,
557	  .scope = OPTIONS_TABLE_WINDOW,
558	  .minimum = 0,
559	  .maximum = INT_MAX,
560	  .default_num = 0
561	},
562
563	{ .name = "force-width",
564	  .type = OPTIONS_TABLE_NUMBER,
565	  .scope = OPTIONS_TABLE_WINDOW,
566	  .minimum = 0,
567	  .maximum = INT_MAX,
568	  .default_num = 0
569	},
570
571	{ .name = "main-pane-height",
572	  .type = OPTIONS_TABLE_NUMBER,
573	  .scope = OPTIONS_TABLE_WINDOW,
574	  .minimum = 1,
575	  .maximum = INT_MAX,
576	  .default_num = 24
577	},
578
579	{ .name = "main-pane-width",
580	  .type = OPTIONS_TABLE_NUMBER,
581	  .scope = OPTIONS_TABLE_WINDOW,
582	  .minimum = 1,
583	  .maximum = INT_MAX,
584	  .default_num = 80
585	},
586
587	{ .name = "mode-attr",
588	  .type = OPTIONS_TABLE_ATTRIBUTES,
589	  .scope = OPTIONS_TABLE_WINDOW,
590	  .default_num = 0,
591	  .style = "mode-style"
592	},
593
594	{ .name = "mode-bg",
595	  .type = OPTIONS_TABLE_COLOUR,
596	  .scope = OPTIONS_TABLE_WINDOW,
597	  .default_num = 3,
598	  .style = "mode-style"
599	},
600
601	{ .name = "mode-fg",
602	  .type = OPTIONS_TABLE_COLOUR,
603	  .scope = OPTIONS_TABLE_WINDOW,
604	  .default_num = 0,
605	  .style = "mode-style"
606	},
607
608	{ .name = "mode-keys",
609	  .type = OPTIONS_TABLE_CHOICE,
610	  .scope = OPTIONS_TABLE_WINDOW,
611	  .choices = options_table_mode_keys_list,
612	  .default_num = MODEKEY_EMACS
613	},
614
615	{ .name = "mode-style",
616	  .type = OPTIONS_TABLE_STYLE,
617	  .scope = OPTIONS_TABLE_WINDOW,
618	  .default_str = "bg=yellow,fg=black"
619	},
620
621	{ .name = "monitor-activity",
622	  .type = OPTIONS_TABLE_FLAG,
623	  .scope = OPTIONS_TABLE_WINDOW,
624	  .default_num = 0
625	},
626
627	{ .name = "monitor-silence",
628	  .type = OPTIONS_TABLE_NUMBER,
629	  .scope = OPTIONS_TABLE_WINDOW,
630	  .minimum = 0,
631	  .maximum = INT_MAX,
632	  .default_num = 0
633	},
634
635	{ .name = "other-pane-height",
636	  .type = OPTIONS_TABLE_NUMBER,
637	  .scope = OPTIONS_TABLE_WINDOW,
638	  .minimum = 0,
639	  .maximum = INT_MAX,
640	  .default_num = 0
641	},
642
643	{ .name = "other-pane-width",
644	  .type = OPTIONS_TABLE_NUMBER,
645	  .scope = OPTIONS_TABLE_WINDOW,
646	  .minimum = 0,
647	  .maximum = INT_MAX,
648	  .default_num = 0
649	},
650
651	{ .name = "pane-active-border-bg",
652	  .type = OPTIONS_TABLE_COLOUR,
653	  .scope = OPTIONS_TABLE_WINDOW,
654	  .default_num = 8,
655	  .style = "pane-active-border-style"
656	},
657
658	{ .name = "pane-active-border-fg",
659	  .type = OPTIONS_TABLE_COLOUR,
660	  .scope = OPTIONS_TABLE_WINDOW,
661	  .default_num = 2,
662	  .style = "pane-active-border-style"
663	},
664
665	{ .name = "pane-active-border-style",
666	  .type = OPTIONS_TABLE_STYLE,
667	  .scope = OPTIONS_TABLE_WINDOW,
668	  .default_str = "fg=green"
669	},
670
671	{ .name = "pane-base-index",
672	  .type = OPTIONS_TABLE_NUMBER,
673	  .scope = OPTIONS_TABLE_WINDOW,
674	  .minimum = 0,
675	  .maximum = USHRT_MAX,
676	  .default_num = 0
677	},
678
679	{ .name = "pane-border-bg",
680	  .type = OPTIONS_TABLE_COLOUR,
681	  .scope = OPTIONS_TABLE_WINDOW,
682	  .default_num = 8,
683	  .style = "pane-border-style"
684	},
685
686	{ .name = "pane-border-fg",
687	  .type = OPTIONS_TABLE_COLOUR,
688	  .scope = OPTIONS_TABLE_WINDOW,
689	  .default_num = 8,
690	  .style = "pane-border-style"
691	},
692
693	{ .name = "pane-border-format",
694	  .type = OPTIONS_TABLE_STRING,
695	  .scope = OPTIONS_TABLE_WINDOW,
696	  .default_str = "#{?pane_active,#[reverse],}#{pane_index}#[default] "
697	                 "\"#{pane_title}\""
698	},
699
700	{ .name = "pane-border-status",
701	  .type = OPTIONS_TABLE_CHOICE,
702	  .scope = OPTIONS_TABLE_WINDOW,
703	  .choices = options_table_pane_status_list,
704	  .default_num = 0
705	},
706
707	{ .name = "pane-border-style",
708	  .type = OPTIONS_TABLE_STYLE,
709	  .scope = OPTIONS_TABLE_WINDOW,
710	  .default_str = "default"
711	},
712
713	{ .name = "remain-on-exit",
714	  .type = OPTIONS_TABLE_FLAG,
715	  .scope = OPTIONS_TABLE_WINDOW,
716	  .default_num = 0
717	},
718
719	{ .name = "synchronize-panes",
720	  .type = OPTIONS_TABLE_FLAG,
721	  .scope = OPTIONS_TABLE_WINDOW,
722	  .default_num = 0
723	},
724
725	{ .name = "window-active-style",
726	  .type = OPTIONS_TABLE_STYLE,
727	  .scope = OPTIONS_TABLE_WINDOW,
728	  .default_str = "default"
729	},
730
731	{ .name = "window-style",
732	  .type = OPTIONS_TABLE_STYLE,
733	  .scope = OPTIONS_TABLE_WINDOW,
734	  .default_str = "default"
735	},
736
737	{ .name = "window-status-activity-attr",
738	  .type = OPTIONS_TABLE_ATTRIBUTES,
739	  .scope = OPTIONS_TABLE_WINDOW,
740	  .default_num = GRID_ATTR_REVERSE,
741	  .style = "window-status-activity-style"
742	},
743
744	{ .name = "window-status-activity-bg",
745	  .type = OPTIONS_TABLE_COLOUR,
746	  .scope = OPTIONS_TABLE_WINDOW,
747	  .default_num = 8,
748	  .style = "window-status-activity-style"
749	},
750
751	{ .name = "window-status-activity-fg",
752	  .type = OPTIONS_TABLE_COLOUR,
753	  .scope = OPTIONS_TABLE_WINDOW,
754	  .default_num = 8,
755	  .style = "window-status-activity-style"
756	},
757
758	{ .name = "window-status-activity-style",
759	  .type = OPTIONS_TABLE_STYLE,
760	  .scope = OPTIONS_TABLE_WINDOW,
761	  .default_str = "reverse"
762	},
763
764	{ .name = "window-status-attr",
765	  .type = OPTIONS_TABLE_ATTRIBUTES,
766	  .scope = OPTIONS_TABLE_WINDOW,
767	  .default_num = 0,
768	  .style = "window-status-style"
769	},
770
771	{ .name = "window-status-bell-attr",
772	  .type = OPTIONS_TABLE_ATTRIBUTES,
773	  .scope = OPTIONS_TABLE_WINDOW,
774	  .default_num = GRID_ATTR_REVERSE,
775	  .style = "window-status-bell-style"
776	},
777
778	{ .name = "window-status-bell-bg",
779	  .type = OPTIONS_TABLE_COLOUR,
780	  .scope = OPTIONS_TABLE_WINDOW,
781	  .default_num = 8,
782	  .style = "window-status-bell-style"
783	},
784
785	{ .name = "window-status-bell-fg",
786	  .type = OPTIONS_TABLE_COLOUR,
787	  .scope = OPTIONS_TABLE_WINDOW,
788	  .default_num = 8,
789	  .style = "window-status-bell-style"
790	},
791
792	{ .name = "window-status-bell-style",
793	  .type = OPTIONS_TABLE_STYLE,
794	  .scope = OPTIONS_TABLE_WINDOW,
795	  .default_str = "reverse"
796	},
797
798	{ .name = "window-status-bg",
799	  .type = OPTIONS_TABLE_COLOUR,
800	  .scope = OPTIONS_TABLE_WINDOW,
801	  .default_num = 8,
802	  .style = "window-status-style"
803	},
804
805	{ .name = "window-status-current-attr",
806	  .type = OPTIONS_TABLE_ATTRIBUTES,
807	  .scope = OPTIONS_TABLE_WINDOW,
808	  .default_num = 0,
809	  .style = "window-status-current-style"
810	},
811
812	{ .name = "window-status-current-bg",
813	  .type = OPTIONS_TABLE_COLOUR,
814	  .scope = OPTIONS_TABLE_WINDOW,
815	  .default_num = 8,
816	  .style = "window-status-current-style"
817	},
818
819	{ .name = "window-status-current-fg",
820	  .type = OPTIONS_TABLE_COLOUR,
821	  .scope = OPTIONS_TABLE_WINDOW,
822	  .default_num = 8,
823	  .style = "window-status-current-style"
824	},
825
826	{ .name = "window-status-current-format",
827	  .type = OPTIONS_TABLE_STRING,
828	  .scope = OPTIONS_TABLE_WINDOW,
829	  .default_str = "#I:#W#{?window_flags,#{window_flags}, }"
830	},
831
832	{ .name = "window-status-current-style",
833	  .type = OPTIONS_TABLE_STYLE,
834	  .scope = OPTIONS_TABLE_WINDOW,
835	  .default_str = "default"
836	},
837
838	{ .name = "window-status-fg",
839	  .type = OPTIONS_TABLE_COLOUR,
840	  .scope = OPTIONS_TABLE_WINDOW,
841	  .default_num = 8,
842	  .style = "window-status-style"
843	},
844
845	{ .name = "window-status-format",
846	  .type = OPTIONS_TABLE_STRING,
847	  .scope = OPTIONS_TABLE_WINDOW,
848	  .default_str = "#I:#W#{?window_flags,#{window_flags}, }"
849	},
850
851	{ .name = "window-status-last-attr",
852	  .type = OPTIONS_TABLE_ATTRIBUTES,
853	  .scope = OPTIONS_TABLE_WINDOW,
854	  .default_num = 0,
855	  .style = "window-status-last-style"
856	},
857
858	{ .name = "window-status-last-bg",
859	  .type = OPTIONS_TABLE_COLOUR,
860	  .scope = OPTIONS_TABLE_WINDOW,
861	  .default_num = 8,
862	  .style = "window-status-last-style"
863	},
864
865	{ .name = "window-status-last-fg",
866	  .type = OPTIONS_TABLE_COLOUR,
867	  .scope = OPTIONS_TABLE_WINDOW,
868	  .default_num = 8,
869	  .style = "window-status-last-style"
870	},
871
872	{ .name = "window-status-last-style",
873	  .type = OPTIONS_TABLE_STYLE,
874	  .scope = OPTIONS_TABLE_WINDOW,
875	  .default_str = "default"
876	},
877
878	{ .name = "window-status-separator",
879	  .type = OPTIONS_TABLE_STRING,
880	  .scope = OPTIONS_TABLE_WINDOW,
881	  .default_str = " "
882	},
883
884	{ .name = "window-status-style",
885	  .type = OPTIONS_TABLE_STYLE,
886	  .scope = OPTIONS_TABLE_WINDOW,
887	  .default_str = "default"
888	},
889
890	{ .name = "wrap-search",
891	  .type = OPTIONS_TABLE_FLAG,
892	  .scope = OPTIONS_TABLE_WINDOW,
893	  .default_num = 1
894	},
895
896	{ .name = "xterm-keys",
897	  .type = OPTIONS_TABLE_FLAG,
898	  .scope = OPTIONS_TABLE_WINDOW,
899	  .default_num = 1
900	},
901
902	{ .name = NULL }
903};
904
905/* Populate an options tree from a table. */
906void
907options_table_populate_tree(enum options_table_scope scope, struct options *oo)
908{
909	const struct options_table_entry	*oe;
910
911	for (oe = options_table; oe->name != NULL; oe++) {
912		if (oe->scope == OPTIONS_TABLE_NONE)
913			fatalx("no scope for %s", oe->name);
914		if (oe->scope != scope)
915			continue;
916		switch (oe->type) {
917		case OPTIONS_TABLE_STRING:
918			options_set_string(oo, oe->name, "%s", oe->default_str);
919			break;
920		case OPTIONS_TABLE_STYLE:
921			options_set_style(oo, oe->name, oe->default_str, 0);
922			break;
923		default:
924			options_set_number(oo, oe->name, oe->default_num);
925			break;
926		}
927	}
928}
929
930/* Print an option using its type from the table. */
931const char *
932options_table_print_entry(const struct options_table_entry *oe,
933    struct options_entry *o, int no_quotes)
934{
935	static char	 out[BUFSIZ];
936	const char	*s;
937
938	*out = '\0';
939	switch (oe->type) {
940	case OPTIONS_TABLE_STRING:
941		if (no_quotes)
942			xsnprintf(out, sizeof out, "%s", o->str);
943		else
944			xsnprintf(out, sizeof out, "\"%s\"", o->str);
945		break;
946	case OPTIONS_TABLE_NUMBER:
947		xsnprintf(out, sizeof out, "%lld", o->num);
948		break;
949	case OPTIONS_TABLE_KEY:
950		xsnprintf(out, sizeof out, "%s",
951		    key_string_lookup_key(o->num));
952		break;
953	case OPTIONS_TABLE_COLOUR:
954		s = colour_tostring(o->num);
955		xsnprintf(out, sizeof out, "%s", s);
956		break;
957	case OPTIONS_TABLE_ATTRIBUTES:
958		s = attributes_tostring(o->num);
959		xsnprintf(out, sizeof out, "%s", s);
960		break;
961	case OPTIONS_TABLE_FLAG:
962		if (o->num)
963			strlcpy(out, "on", sizeof out);
964		else
965			strlcpy(out, "off", sizeof out);
966		break;
967	case OPTIONS_TABLE_CHOICE:
968		s = oe->choices[o->num];
969		xsnprintf(out, sizeof out, "%s", s);
970		break;
971	case OPTIONS_TABLE_STYLE:
972		s = style_tostring(&o->style);
973		xsnprintf(out, sizeof out, "%s", s);
974		break;
975	}
976	return (out);
977}
978
979/* Find an option. */
980int
981options_table_find(const char *optstr, const struct options_table_entry **oe)
982{
983	const struct options_table_entry	*oe_loop;
984
985	for (oe_loop = options_table; oe_loop->name != NULL; oe_loop++) {
986		if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
987			continue;
988
989		/* If already found, ambiguous. */
990		if (*oe != NULL)
991			return (-1);
992		*oe = oe_loop;
993
994		/* Bail now if an exact match. */
995		if (strcmp(oe_loop->name, optstr) == 0)
996			break;
997	}
998	return (0);
999}
1000