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

Annotation of src/usr.bin/tmux/format.c, Revision 1.44

1.44    ! nicm        1: /* $OpenBSD: format.c,v 1.43 2014/04/17 07:36:45 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:
1.30      nicm       21: #include <ctype.h>
                     22: #include <errno.h>
1.1       nicm       23: #include <netdb.h>
                     24: #include <stdarg.h>
1.9       nicm       25: #include <stdlib.h>
1.1       nicm       26: #include <string.h>
                     27: #include <time.h>
                     28: #include <unistd.h>
                     29:
                     30: #include "tmux.h"
                     31:
                     32: /*
                     33:  * Build a list of key-value pairs and use them to expand #{key} entries in a
                     34:  * string.
                     35:  */
                     36:
1.32      nicm       37: int     format_replace(struct format_tree *, const char *, size_t, char **,
                     38:             size_t *, size_t *);
                     39: char   *format_get_command(struct window_pane *);
                     40: void    format_window_pane_tabs(struct format_tree *, struct window_pane *);
1.1       nicm       41:
                     42: /* Format key-value replacement entry. */
                     43: RB_GENERATE(format_tree, format_entry, entry, format_cmp);
                     44:
                     45: /* Format tree comparison function. */
                     46: int
                     47: format_cmp(struct format_entry *fe1, struct format_entry *fe2)
                     48: {
                     49:        return (strcmp(fe1->key, fe2->key));
                     50: }
                     51:
1.25      nicm       52: /* Single-character uppercase aliases. */
                     53: const char *format_upper[] = {
1.1       nicm       54:        NULL,           /* A */
                     55:        NULL,           /* B */
                     56:        NULL,           /* C */
                     57:        "pane_id",      /* D */
                     58:        NULL,           /* E */
                     59:        "window_flags", /* F */
                     60:        NULL,           /* G */
                     61:        "host",         /* H */
                     62:        "window_index", /* I */
                     63:        NULL,           /* J */
                     64:        NULL,           /* K */
                     65:        NULL,           /* L */
                     66:        NULL,           /* M */
                     67:        NULL,           /* N */
                     68:        NULL,           /* O */
                     69:        "pane_index",   /* P */
                     70:        NULL,           /* Q */
                     71:        NULL,           /* R */
                     72:        "session_name", /* S */
                     73:        "pane_title",   /* T */
                     74:        NULL,           /* U */
                     75:        NULL,           /* V */
                     76:        "window_name",  /* W */
                     77:        NULL,           /* X */
                     78:        NULL,           /* Y */
                     79:        NULL            /* Z */
                     80: };
                     81:
1.25      nicm       82: /* Single-character lowercase aliases. */
                     83: const char *format_lower[] = {
                     84:        NULL,           /* a */
                     85:        NULL,           /* b */
                     86:        NULL,           /* c */
                     87:        NULL,           /* d */
                     88:        NULL,           /* e */
                     89:        NULL,           /* f */
                     90:        NULL,           /* g */
                     91:        "host_short",   /* h */
                     92:        NULL,           /* i */
                     93:        NULL,           /* j */
                     94:        NULL,           /* k */
                     95:        NULL,           /* l */
                     96:        NULL,           /* m */
                     97:        NULL,           /* n */
                     98:        NULL,           /* o */
                     99:        NULL,           /* p */
                    100:        NULL,           /* q */
                    101:        NULL,           /* r */
                    102:        NULL,           /* s */
                    103:        NULL,           /* t */
                    104:        NULL,           /* u */
                    105:        NULL,           /* v */
                    106:        NULL,           /* w */
                    107:        NULL,           /* x */
                    108:        NULL,           /* y */
                    109:        NULL            /* z */
                    110: };
                    111:
1.1       nicm      112: /* Create a new tree. */
                    113: struct format_tree *
                    114: format_create(void)
                    115: {
                    116:        struct format_tree      *ft;
1.25      nicm      117:        char                     host[MAXHOSTNAMELEN], *ptr;
1.1       nicm      118:
                    119:        ft = xmalloc(sizeof *ft);
                    120:        RB_INIT(ft);
                    121:
1.25      nicm      122:        if (gethostname(host, sizeof host) == 0) {
1.1       nicm      123:                format_add(ft, "host", "%s", host);
1.33      nicm      124:                if ((ptr = strchr(host, '.')) != NULL)
1.25      nicm      125:                        *ptr = '\0';
                    126:                format_add(ft, "host_short", "%s", host);
                    127:        }
1.1       nicm      128:
                    129:        return (ft);
                    130: }
                    131:
                    132: /* Free a tree. */
                    133: void
                    134: format_free(struct format_tree *ft)
                    135: {
                    136:        struct format_entry     *fe, *fe_next;
                    137:
                    138:        fe_next = RB_MIN(format_tree, ft);
                    139:        while (fe_next != NULL) {
                    140:                fe = fe_next;
                    141:                fe_next = RB_NEXT(format_tree, ft, fe);
                    142:
                    143:                RB_REMOVE(format_tree, ft, fe);
1.9       nicm      144:                free(fe->value);
                    145:                free(fe->key);
                    146:                free(fe);
1.1       nicm      147:        }
                    148:
1.25      nicm      149:        free(ft);
1.1       nicm      150: }
                    151:
                    152: /* Add a key-value pair. */
                    153: void
                    154: format_add(struct format_tree *ft, const char *key, const char *fmt, ...)
                    155: {
                    156:        struct format_entry     *fe;
1.28      nicm      157:        struct format_entry     *fe_now;
1.1       nicm      158:        va_list                  ap;
                    159:
                    160:        fe = xmalloc(sizeof *fe);
                    161:        fe->key = xstrdup(key);
                    162:
                    163:        va_start(ap, fmt);
                    164:        xvasprintf(&fe->value, fmt, ap);
                    165:        va_end(ap);
                    166:
1.28      nicm      167:        fe_now = RB_INSERT(format_tree, ft, fe);
                    168:        if (fe_now != NULL) {
                    169:                free(fe_now->value);
                    170:                fe_now->value = fe->value;
                    171:                free(fe->key);
                    172:                free(fe);
                    173:        }
1.1       nicm      174: }
                    175:
                    176: /* Find a format entry. */
                    177: const char *
                    178: format_find(struct format_tree *ft, const char *key)
                    179: {
                    180:        struct format_entry     *fe, fe_find;
                    181:
                    182:        fe_find.key = (char *) key;
                    183:        fe = RB_FIND(format_tree, ft, &fe_find);
                    184:        if (fe == NULL)
                    185:                return (NULL);
                    186:        return (fe->value);
                    187: }
                    188:
                    189: /*
                    190:  * Replace a key/value pair in buffer. #{blah} is expanded directly,
                    191:  * #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
                    192:  */
                    193: int
1.30      nicm      194: format_replace(struct format_tree *ft, const char *key, size_t keylen,
                    195:     char **buf, size_t *len, size_t *off)
1.1       nicm      196: {
1.44    ! nicm      197:        char            *copy, *copy0, *endptr, *ptr, *saved, *trimmed;
1.1       nicm      198:        const char      *value;
                    199:        size_t           valuelen;
1.44    ! nicm      200:        u_long           limit = 0;
1.1       nicm      201:
                    202:        /* Make a copy of the key. */
1.30      nicm      203:        copy0 = copy = xmalloc(keylen + 1);
1.1       nicm      204:        memcpy(copy, key, keylen);
                    205:        copy[keylen] = '\0';
                    206:
1.30      nicm      207:        /* Is there a length limit or whatnot? */
                    208:        if (!islower((u_char) *copy) && *copy != '?') {
                    209:                while (*copy != ':' && *copy != '\0') {
                    210:                        switch (*copy) {
                    211:                        case '=':
                    212:                                errno = 0;
                    213:                                limit = strtoul(copy + 1, &endptr, 10);
                    214:                                if (errno == ERANGE && limit == ULONG_MAX)
                    215:                                        goto fail;
                    216:                                copy = endptr;
                    217:                                break;
                    218:                        default:
                    219:                                copy++;
                    220:                                break;
                    221:                        }
                    222:                }
                    223:                if (*copy != ':')
                    224:                        goto fail;
                    225:                copy++;
                    226:        }
                    227:
1.1       nicm      228:        /*
                    229:         * Is this a conditional? If so, check it exists and extract either the
                    230:         * first or second element. If not, look up the key directly.
                    231:         */
                    232:        if (*copy == '?') {
                    233:                ptr = strchr(copy, ',');
                    234:                if (ptr == NULL)
                    235:                        goto fail;
                    236:                *ptr = '\0';
                    237:
                    238:                value = format_find(ft, copy + 1);
                    239:                if (value != NULL && (value[0] != '0' || value[1] != '\0')) {
                    240:                        value = ptr + 1;
                    241:                        ptr = strchr(value, ',');
                    242:                        if (ptr == NULL)
                    243:                                goto fail;
                    244:                        *ptr = '\0';
                    245:                } else {
                    246:                        ptr = strchr(ptr + 1, ',');
                    247:                        if (ptr == NULL)
                    248:                                goto fail;
                    249:                        value = ptr + 1;
                    250:                }
1.31      nicm      251:                saved = format_expand(ft, value);
                    252:                value = saved;
1.1       nicm      253:        } else {
                    254:                value = format_find(ft, copy);
                    255:                if (value == NULL)
                    256:                        value = "";
1.31      nicm      257:                saved = NULL;
1.1       nicm      258:        }
                    259:
1.30      nicm      260:        /* Truncate the value if needed. */
1.44    ! nicm      261:        if (limit != 0) {
        !           262:                value = trimmed = utf8_trimcstr(value, limit);
        !           263:                free(saved);
        !           264:                saved = trimmed;
        !           265:        }
        !           266:        valuelen = strlen(value);
1.30      nicm      267:
1.1       nicm      268:        /* Expand the buffer and copy in the value. */
                    269:        while (*len - *off < valuelen + 1) {
                    270:                *buf = xrealloc(*buf, 2, *len);
                    271:                *len *= 2;
                    272:        }
                    273:        memcpy(*buf + *off, value, valuelen);
                    274:        *off += valuelen;
                    275:
1.31      nicm      276:        free(saved);
1.30      nicm      277:        free(copy0);
1.1       nicm      278:        return (0);
                    279:
                    280: fail:
1.30      nicm      281:        free(copy0);
1.1       nicm      282:        return (-1);
                    283: }
                    284:
                    285: /* Expand keys in a template. */
                    286: char *
                    287: format_expand(struct format_tree *ft, const char *fmt)
                    288: {
1.31      nicm      289:        char            *buf;
                    290:        const char      *ptr, *s;
1.1       nicm      291:        size_t           off, len, n;
1.31      nicm      292:        int              ch, brackets;
1.1       nicm      293:
                    294:        len = 64;
                    295:        buf = xmalloc(len);
                    296:        off = 0;
                    297:
                    298:        while (*fmt != '\0') {
                    299:                if (*fmt != '#') {
                    300:                        while (len - off < 2) {
                    301:                                buf = xrealloc(buf, 2, len);
                    302:                                len *= 2;
                    303:                        }
                    304:                        buf[off++] = *fmt++;
                    305:                        continue;
                    306:                }
                    307:                fmt++;
                    308:
                    309:                ch = (u_char) *fmt++;
                    310:                switch (ch) {
                    311:                case '{':
1.31      nicm      312:                        brackets = 1;
                    313:                        for (ptr = fmt; *ptr != '\0'; ptr++) {
                    314:                                if (*ptr == '{')
                    315:                                        brackets++;
                    316:                                if (*ptr == '}' && --brackets == 0)
                    317:                                        break;
                    318:                        }
                    319:                        if (*ptr != '}' || brackets != 0)
1.1       nicm      320:                                break;
                    321:                        n = ptr - fmt;
                    322:
                    323:                        if (format_replace(ft, fmt, n, &buf, &len, &off) != 0)
                    324:                                break;
                    325:                        fmt += n + 1;
1.40      nicm      326:                        continue;
                    327:                case '#':
                    328:                        while (len - off < 2) {
                    329:                                buf = xrealloc(buf, 2, len);
                    330:                                len *= 2;
                    331:                        }
                    332:                        buf[off++] = '#';
1.1       nicm      333:                        continue;
                    334:                default:
1.25      nicm      335:                        s = NULL;
                    336:                        if (ch >= 'A' && ch <= 'Z')
                    337:                                s = format_upper[ch - 'A'];
                    338:                        else if (ch >= 'a' && ch <= 'z')
                    339:                                s = format_lower[ch - 'a'];
                    340:                        if (s == NULL) {
                    341:                                while (len - off < 3) {
                    342:                                        buf = xrealloc(buf, 2, len);
                    343:                                        len *= 2;
1.1       nicm      344:                                }
1.25      nicm      345:                                buf[off++] = '#';
                    346:                                buf[off++] = ch;
                    347:                                continue;
1.1       nicm      348:                        }
1.25      nicm      349:                        n = strlen(s);
                    350:                        if (format_replace(ft, s, n, &buf, &len, &off) != 0)
                    351:                                break;
1.1       nicm      352:                        continue;
                    353:                }
                    354:
                    355:                break;
                    356:        }
                    357:        buf[off] = '\0';
                    358:
                    359:        return (buf);
                    360: }
                    361:
1.32      nicm      362: /* Get command name for format. */
                    363: char *
                    364: format_get_command(struct window_pane *wp)
                    365: {
1.37      nicm      366:        char    *cmd, *out;
1.32      nicm      367:
                    368:        cmd = get_proc_name(wp->fd, wp->tty);
                    369:        if (cmd == NULL || *cmd == '\0') {
1.39      nicm      370:                free(cmd);
1.38      nicm      371:                cmd = xstrdup(wp->cmd);
1.39      nicm      372:                if (cmd == NULL || *cmd == '\0') {
                    373:                        free(cmd);
1.38      nicm      374:                        cmd = xstrdup(wp->shell);
1.39      nicm      375:                }
1.32      nicm      376:        }
1.37      nicm      377:        out = parse_window_name(cmd);
                    378:        free(cmd);
                    379:        return (out);
1.32      nicm      380: }
                    381:
1.1       nicm      382: /* Set default format keys for a session. */
                    383: void
                    384: format_session(struct format_tree *ft, struct session *s)
                    385: {
                    386:        struct session_group    *sg;
                    387:        char                    *tim;
                    388:        time_t                   t;
                    389:
                    390:        format_add(ft, "session_name", "%s", s->name);
                    391:        format_add(ft, "session_windows", "%u", winlink_count(&s->windows));
                    392:        format_add(ft, "session_width", "%u", s->sx);
                    393:        format_add(ft, "session_height", "%u", s->sy);
1.23      nicm      394:        format_add(ft, "session_id", "$%u", s->id);
1.1       nicm      395:
                    396:        sg = session_group_find(s);
                    397:        format_add(ft, "session_grouped", "%d", sg != NULL);
                    398:        if (sg != NULL)
                    399:                format_add(ft, "session_group", "%u", session_group_index(sg));
                    400:
                    401:        t = s->creation_time.tv_sec;
1.24      deraadt   402:        format_add(ft, "session_created", "%lld", (long long) t);
1.1       nicm      403:        tim = ctime(&t);
                    404:        *strchr(tim, '\n') = '\0';
                    405:        format_add(ft, "session_created_string", "%s", tim);
                    406:
1.41      nicm      407:        format_add(ft, "session_attached", "%u", s->attached);
                    408:        format_add(ft, "session_many_attached", "%u", s->attached > 1);
1.3       nicm      409: }
                    410:
                    411: /* Set default format keys for a client. */
                    412: void
                    413: format_client(struct format_tree *ft, struct client *c)
                    414: {
1.15      nicm      415:        char            *tim;
                    416:        time_t           t;
                    417:        struct session  *s;
1.3       nicm      418:
1.6       nicm      419:        format_add(ft, "client_height", "%u", c->tty.sy);
                    420:        format_add(ft, "client_width", "%u", c->tty.sx);
1.27      nicm      421:        if (c->tty.path != NULL)
                    422:                format_add(ft, "client_tty", "%s", c->tty.path);
                    423:        if (c->tty.termname != NULL)
                    424:                format_add(ft, "client_termname", "%s", c->tty.termname);
1.3       nicm      425:
                    426:        t = c->creation_time.tv_sec;
1.24      deraadt   427:        format_add(ft, "client_created", "%lld", (long long) t);
1.3       nicm      428:        tim = ctime(&t);
                    429:        *strchr(tim, '\n') = '\0';
                    430:        format_add(ft, "client_created_string", "%s", tim);
                    431:
                    432:        t = c->activity_time.tv_sec;
1.24      deraadt   433:        format_add(ft, "client_activity", "%lld", (long long) t);
1.3       nicm      434:        tim = ctime(&t);
                    435:        *strchr(tim, '\n') = '\0';
                    436:        format_add(ft, "client_activity_string", "%s", tim);
1.14      nicm      437:
                    438:        format_add(ft, "client_prefix", "%d", !!(c->flags & CLIENT_PREFIX));
1.3       nicm      439:
                    440:        if (c->tty.flags & TTY_UTF8)
                    441:                format_add(ft, "client_utf8", "%d", 1);
                    442:        else
                    443:                format_add(ft, "client_utf8", "%d", 0);
                    444:
                    445:        if (c->flags & CLIENT_READONLY)
                    446:                format_add(ft, "client_readonly", "%d", 1);
                    447:        else
                    448:                format_add(ft, "client_readonly", "%d", 0);
1.15      nicm      449:
                    450:        s = c->session;
                    451:        if (s != NULL)
                    452:                format_add(ft, "client_session", "%s", s->name);
                    453:        s = c->last_session;
                    454:        if (s != NULL && session_alive(s))
                    455:                format_add(ft, "client_last_session", "%s", s->name);
1.1       nicm      456: }
                    457:
1.32      nicm      458: /* Set default format keys for a window. */
                    459: void
                    460: format_window(struct format_tree *ft, struct window *w)
                    461: {
                    462:        char    *layout;
                    463:
                    464:        layout = layout_dump(w);
                    465:
                    466:        format_add(ft, "window_id", "@%u", w->id);
                    467:        format_add(ft, "window_name", "%s", w->name);
                    468:        format_add(ft, "window_width", "%u", w->sx);
                    469:        format_add(ft, "window_height", "%u", w->sy);
                    470:        format_add(ft, "window_layout", "%s", layout);
                    471:        format_add(ft, "window_panes", "%u", window_count_panes(w));
                    472:
                    473:        free(layout);
                    474: }
                    475:
1.1       nicm      476: /* Set default format keys for a winlink. */
                    477: void
                    478: format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
                    479: {
                    480:        struct window   *w = wl->window;
1.32      nicm      481:        char            *flags;
1.1       nicm      482:
                    483:        flags = window_printable_flags(s, wl);
                    484:
1.32      nicm      485:        format_window(ft, w);
                    486:
1.1       nicm      487:        format_add(ft, "window_index", "%d", wl->idx);
                    488:        format_add(ft, "window_flags", "%s", flags);
                    489:        format_add(ft, "window_active", "%d", wl == s->curw);
1.29      nicm      490:
                    491:        format_add(ft, "window_bell_flag", "%u",
                    492:            !!(wl->flags & WINLINK_BELL));
                    493:        format_add(ft, "window_activity_flag", "%u",
                    494:            !!(wl->flags & WINLINK_ACTIVITY));
                    495:        format_add(ft, "window_silence_flag", "%u",
                    496:            !!(wl->flags & WINLINK_SILENCE));
1.1       nicm      497:
1.32      nicm      498:
1.9       nicm      499:        free(flags);
1.1       nicm      500: }
                    501:
1.19      nicm      502: /* Add window pane tabs. */
                    503: void
                    504: format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
                    505: {
                    506:        struct evbuffer *buffer;
                    507:        u_int            i;
                    508:
                    509:        buffer = evbuffer_new();
                    510:        for (i = 0; i < wp->base.grid->sx; i++) {
                    511:                if (!bit_test(wp->base.tabs, i))
                    512:                        continue;
                    513:
                    514:                if (EVBUFFER_LENGTH(buffer) > 0)
                    515:                        evbuffer_add(buffer, ",", 1);
                    516:                evbuffer_add_printf(buffer, "%d", i);
                    517:        }
                    518:
                    519:        format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer),
                    520:            EVBUFFER_DATA(buffer));
                    521:        evbuffer_free(buffer);
                    522: }
                    523:
1.1       nicm      524: /* Set default format keys for a window pane. */
                    525: void
                    526: format_window_pane(struct format_tree *ft, struct window_pane *wp)
                    527: {
                    528:        struct grid             *gd = wp->base.grid;
                    529:        struct grid_line        *gl;
                    530:        unsigned long long       size;
1.20      nicm      531:        u_int                    i, idx;
1.21      nicm      532:        char                    *cmd;
1.1       nicm      533:
                    534:        size = 0;
                    535:        for (i = 0; i < gd->hsize; i++) {
                    536:                gl = &gd->linedata[i];
                    537:                size += gl->cellsize * sizeof *gl->celldata;
                    538:        }
                    539:        size += gd->hsize * sizeof *gd->linedata;
1.16      nicm      540:        format_add(ft, "history_size", "%u", gd->hsize);
                    541:        format_add(ft, "history_limit", "%u", gd->hlimit);
                    542:        format_add(ft, "history_bytes", "%llu", size);
1.1       nicm      543:
1.4       nicm      544:        if (window_pane_index(wp, &idx) != 0)
                    545:                fatalx("index not found");
1.16      nicm      546:        format_add(ft, "pane_index", "%u", idx);
1.4       nicm      547:
1.1       nicm      548:        format_add(ft, "pane_width", "%u", wp->sx);
                    549:        format_add(ft, "pane_height", "%u", wp->sy);
                    550:        format_add(ft, "pane_title", "%s", wp->base.title);
                    551:        format_add(ft, "pane_id", "%%%u", wp->id);
                    552:        format_add(ft, "pane_active", "%d", wp == wp->window->active);
                    553:        format_add(ft, "pane_dead", "%d", wp->fd == -1);
1.16      nicm      554:
                    555:        format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
1.26      nicm      556:        format_add(ft, "pane_synchronized", "%d",
                    557:            !!options_get_number(&wp->window->options, "synchronize-panes"));
1.16      nicm      558:
                    559:        if (wp->tty != NULL)
                    560:                format_add(ft, "pane_tty", "%s", wp->tty);
                    561:        format_add(ft, "pane_pid", "%ld", (long) wp->pid);
1.2       nicm      562:        if (wp->cmd != NULL)
                    563:                format_add(ft, "pane_start_command", "%s", wp->cmd);
1.35      nicm      564:        if ((cmd = format_get_command(wp)) != NULL) {
1.17      nicm      565:                format_add(ft, "pane_current_command", "%s", cmd);
1.21      nicm      566:                free(cmd);
                    567:        }
1.16      nicm      568:
                    569:        format_add(ft, "cursor_x", "%d", wp->base.cx);
                    570:        format_add(ft, "cursor_y", "%d", wp->base.cy);
                    571:        format_add(ft, "scroll_region_upper", "%d", wp->base.rupper);
                    572:        format_add(ft, "scroll_region_lower", "%d", wp->base.rlower);
                    573:        format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx);
                    574:        format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy);
                    575:
                    576:        format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
                    577:        format_add(ft, "alternate_saved_x", "%d", wp->saved_cx);
                    578:        format_add(ft, "alternate_saved_y", "%d", wp->saved_cy);
                    579:
                    580:        format_add(ft, "cursor_flag", "%d",
                    581:            !!(wp->base.mode & MODE_CURSOR));
                    582:        format_add(ft, "insert_flag", "%d",
                    583:            !!(wp->base.mode & MODE_INSERT));
                    584:        format_add(ft, "keypad_cursor_flag", "%d",
                    585:            !!(wp->base.mode & MODE_KCURSOR));
                    586:        format_add(ft, "keypad_flag", "%d",
                    587:            !!(wp->base.mode & MODE_KKEYPAD));
                    588:        format_add(ft, "wrap_flag", "%d",
                    589:            !!(wp->base.mode & MODE_WRAP));
                    590:
                    591:        format_add(ft, "mouse_standard_flag", "%d",
                    592:            !!(wp->base.mode & MODE_MOUSE_STANDARD));
                    593:        format_add(ft, "mouse_button_flag", "%d",
                    594:            !!(wp->base.mode & MODE_MOUSE_BUTTON));
                    595:        format_add(ft, "mouse_any_flag", "%d",
                    596:            !!(wp->base.mode & MODE_MOUSE_ANY));
                    597:        format_add(ft, "mouse_utf8_flag", "%d",
                    598:            !!(wp->base.mode & MODE_MOUSE_UTF8));
1.19      nicm      599:
                    600:        format_window_pane_tabs(ft, wp);
1.8       nicm      601: }
                    602:
1.19      nicm      603: /* Set default format keys for paste buffer. */
1.8       nicm      604: void
1.42      nicm      605: format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb,
                    606:     int utf8flag)
1.8       nicm      607: {
1.42      nicm      608:        char    *s;
1.8       nicm      609:
                    610:        format_add(ft, "buffer_size", "%zu", pb->size);
                    611:
1.42      nicm      612:        s = paste_make_sample(pb, utf8flag);
                    613:        format_add(ft, "buffer_sample", "%s", s);
                    614:        free(s);
1.1       nicm      615: }