From 86adcd4b2666344e9e77fc8f27ab8124557713f2 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:29:40 +0000 Subject: [PATCH] Add pane_tabs format to format_window_pane based on code from George Nachman. --- format.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/format.c b/format.c index 7e442e0a..4c93c766 100644 --- a/format.c +++ b/format.c @@ -32,8 +32,9 @@ * string. */ -int format_replace(struct format_tree *, - const char *, size_t, char **, size_t *, size_t *); +int format_replace(struct format_tree *, const char *, size_t, char **, + size_t *, size_t *); +void format_window_pane_tabs(struct format_tree *, struct window_pane *); /* Format key-value replacement entry. */ 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); } +/* 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. */ void 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 idx; const char *cwd; + const char *cmd; size = 0; 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); if ((cwd = get_proc_cwd(wp->fd)) != NULL) 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_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)); format_add(ft, "mouse_utf8_flag", "%d", !!(wp->base.mode & MODE_MOUSE_UTF8)); + + format_window_pane_tabs(ft, wp); } +/* Set default format keys for paste buffer. */ void format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb) {