[BACK]Return to options-table.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/options-table.c, Revision 1.38

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