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