Add pane_tabs format to format_window_pane based on code from George

Nachman.
This commit is contained in:
Nicholas Marriott 2013-03-24 09:29:40 +00:00
parent a60687f9ba
commit 86adcd4b26

View File

@ -32,8 +32,9 @@
* string. * string.
*/ */
int format_replace(struct format_tree *, int format_replace(struct format_tree *, const char *, size_t, char **,
const char *, size_t, char **, size_t *, size_t *); size_t *, size_t *);
void format_window_pane_tabs(struct format_tree *, struct window_pane *);
/* Format key-value replacement entry. */ /* Format key-value replacement entry. */
RB_GENERATE(format_tree, format_entry, entry, format_cmp); RB_GENERATE(format_tree, format_entry, entry, format_cmp);
@ -367,6 +368,28 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
free(layout); free(layout);
} }
/* Add window pane tabs. */
void
format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
{
struct evbuffer *buffer;
u_int i;
buffer = evbuffer_new();
for (i = 0; i < wp->base.grid->sx; i++) {
if (!bit_test(wp->base.tabs, i))
continue;
if (EVBUFFER_LENGTH(buffer) > 0)
evbuffer_add(buffer, ",", 1);
evbuffer_add_printf(buffer, "%d", i);
}
format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer),
EVBUFFER_DATA(buffer));
evbuffer_free(buffer);
}
/* Set default format keys for a window pane. */ /* Set default format keys for a window pane. */
void void
format_window_pane(struct format_tree *ft, struct window_pane *wp) format_window_pane(struct format_tree *ft, struct window_pane *wp)
@ -377,6 +400,7 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
u_int i; u_int i;
u_int idx; u_int idx;
const char *cwd; const char *cwd;
const char *cmd;
size = 0; size = 0;
for (i = 0; i < gd->hsize; i++) { for (i = 0; i < gd->hsize; i++) {
@ -410,6 +434,8 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "pane_start_path", "%s", wp->cwd); format_add(ft, "pane_start_path", "%s", wp->cwd);
if ((cwd = get_proc_cwd(wp->fd)) != NULL) if ((cwd = get_proc_cwd(wp->fd)) != NULL)
format_add(ft, "pane_current_path", "%s", cwd); format_add(ft, "pane_current_path", "%s", cwd);
if ((cmd = get_proc_name(wp->fd, wp->tty)) != NULL)
format_add(ft, "pane_current_command", "%s", cmd);
format_add(ft, "cursor_x", "%d", wp->base.cx); format_add(ft, "cursor_x", "%d", wp->base.cx);
format_add(ft, "cursor_y", "%d", wp->base.cy); format_add(ft, "cursor_y", "%d", wp->base.cy);
@ -441,8 +467,11 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
!!(wp->base.mode & MODE_MOUSE_ANY)); !!(wp->base.mode & MODE_MOUSE_ANY));
format_add(ft, "mouse_utf8_flag", "%d", format_add(ft, "mouse_utf8_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_UTF8)); !!(wp->base.mode & MODE_MOUSE_UTF8));
format_window_pane_tabs(ft, wp);
} }
/* Set default format keys for paste buffer. */
void void
format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb) format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb)
{ {