[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.6

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