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