From 63b4fd5cacc1a53b93e92ef007d5a7249f5cac38 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 21 Mar 2013 16:14:09 +0000 Subject: Add a format client_prefix which is 1 if prefix key has been pressed, used for example #{?client_prefix,X,Y}. Also a few extra server_client_status needed. --- format.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'format.c') diff --git a/format.c b/format.c index e950df53..f005c1c4 100644 --- a/format.c +++ b/format.c @@ -251,10 +251,11 @@ format_expand(struct format_tree *ft, const char *fmt) continue; } } - while (len - off < 2) { + while (len - off < 3) { buf = xrealloc(buf, 2, len); len *= 2; } + buf[off++] = '#'; buf[off++] = ch; continue; } @@ -321,6 +322,8 @@ format_client(struct format_tree *ft, struct client *c) *strchr(tim, '\n') = '\0'; format_add(ft, "client_activity_string", "%s", tim); + format_add(ft, "client_prefix", "%d", !!(c->flags & CLIENT_PREFIX)); + if (c->tty.flags & TTY_UTF8) format_add(ft, "client_utf8", "%d", 1); else -- cgit From ad760b3bf702801eaa121715f2a283526d614913 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 10:32:36 +0000 Subject: Add client_session and client_last_session formats. --- format.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index f005c1c4..9e3bc86a 100644 --- a/format.c +++ b/format.c @@ -301,8 +301,9 @@ format_session(struct format_tree *ft, struct session *s) void format_client(struct format_tree *ft, struct client *c) { - char *tim; - time_t t; + char *tim; + time_t t; + struct session *s; format_add(ft, "client_cwd", "%s", c->cwd); format_add(ft, "client_height", "%u", c->tty.sy); @@ -333,6 +334,13 @@ format_client(struct format_tree *ft, struct client *c) format_add(ft, "client_readonly", "%d", 1); else format_add(ft, "client_readonly", "%d", 0); + + s = c->session; + if (s != NULL) + format_add(ft, "client_session", "%s", s->name); + s = c->last_session; + if (s != NULL && session_alive(s)) + format_add(ft, "client_last_session", "%s", s->name); } /* Set default format keys for a winlink. */ -- cgit From 702ab8bab0e88613aa0e6e6cf8a2e18fdd47341a Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 16:03:35 +0000 Subject: Add a load of miscellaneous pane formats, from George Nachman. --- format.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 9e3bc86a..7e442e0a 100644 --- a/format.c +++ b/format.c @@ -384,29 +384,63 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) size += gl->cellsize * sizeof *gl->celldata; } size += gd->hsize * sizeof *gd->linedata; + format_add(ft, "history_size", "%u", gd->hsize); + format_add(ft, "history_limit", "%u", gd->hlimit); + format_add(ft, "history_bytes", "%llu", size); if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); + format_add(ft, "pane_index", "%u", idx); format_add(ft, "pane_width", "%u", wp->sx); format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); - format_add(ft, "pane_index", "%u", idx); - format_add(ft, "history_size", "%u", gd->hsize); - format_add(ft, "history_limit", "%u", gd->hlimit); - format_add(ft, "history_bytes", "%llu", size); format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == wp->window->active); format_add(ft, "pane_dead", "%d", wp->fd == -1); + + format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base); + + if (wp->tty != NULL) + format_add(ft, "pane_tty", "%s", wp->tty); + format_add(ft, "pane_pid", "%ld", (long) wp->pid); if (wp->cmd != NULL) format_add(ft, "pane_start_command", "%s", wp->cmd); if (wp->cwd != NULL) 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); - format_add(ft, "pane_pid", "%ld", (long) wp->pid); - if (wp->tty != NULL) - format_add(ft, "pane_tty", "%s", wp->tty); + + format_add(ft, "cursor_x", "%d", wp->base.cx); + format_add(ft, "cursor_y", "%d", wp->base.cy); + format_add(ft, "scroll_region_upper", "%d", wp->base.rupper); + format_add(ft, "scroll_region_lower", "%d", wp->base.rlower); + format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx); + format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy); + + format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); + format_add(ft, "alternate_saved_x", "%d", wp->saved_cx); + format_add(ft, "alternate_saved_y", "%d", wp->saved_cy); + + format_add(ft, "cursor_flag", "%d", + !!(wp->base.mode & MODE_CURSOR)); + format_add(ft, "insert_flag", "%d", + !!(wp->base.mode & MODE_INSERT)); + format_add(ft, "keypad_cursor_flag", "%d", + !!(wp->base.mode & MODE_KCURSOR)); + format_add(ft, "keypad_flag", "%d", + !!(wp->base.mode & MODE_KKEYPAD)); + format_add(ft, "wrap_flag", "%d", + !!(wp->base.mode & MODE_WRAP)); + + format_add(ft, "mouse_standard_flag", "%d", + !!(wp->base.mode & MODE_MOUSE_STANDARD)); + format_add(ft, "mouse_button_flag", "%d", + !!(wp->base.mode & MODE_MOUSE_BUTTON)); + format_add(ft, "mouse_any_flag", "%d", + !!(wp->base.mode & MODE_MOUSE_ANY)); + format_add(ft, "mouse_utf8_flag", "%d", + !!(wp->base.mode & MODE_MOUSE_UTF8)); } void -- cgit From 86adcd4b2666344e9e77fc8f27ab8124557713f2 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:29:40 +0000 Subject: Add pane_tabs format to format_window_pane based on code from George Nachman. --- format.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'format.c') 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) { -- cgit From 20636d956dd36c1f14152569a4d44a50eea9083d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:54:10 +0000 Subject: Add a command queue to standardize and simplify commands that call other commands and allow a command to block execution of subsequent commands. This allows run-shell and if-shell to be synchronous which has been much requested. Each client has a default command queue and commands are consumed one at a time from it. A command may suspend execution from the queue by returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() - for example run-shell does this from the callback that is fired after the job is freed. When the command queue becomes empty, command clients are automatically exited (unless attaching). A callback is also fired - this is used for nested commands in, for example, if-shell which can block execution of the client's cmdq until a new cmdq becomes empty. Also merge all the old error/info/print functions together and lose the old curclient/cmdclient distinction - a cmdq is bound to one client (or none if in the configuration file), this is a command client if c->session is NULL otherwise an attached client. --- format.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 4c93c766..af2c128b 100644 --- a/format.c +++ b/format.c @@ -397,10 +397,8 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) struct grid *gd = wp->base.grid; struct grid_line *gl; unsigned long long size; - u_int i; - u_int idx; - const char *cwd; - const char *cmd; + u_int i, idx; + const char *cwd, *cmd; size = 0; for (i = 0; i < gd->hsize; i++) { -- cgit From 35452b3e55aeaba7d64f604e32b31c80d3f80fde Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 25 Mar 2013 10:07:21 +0000 Subject: Do not leak command in formats, from Romain Francoise. --- format.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index af2c128b..11f003c8 100644 --- a/format.c +++ b/format.c @@ -398,7 +398,8 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) struct grid_line *gl; unsigned long long size; u_int i, idx; - const char *cwd, *cmd; + const char *cwd; + char *cmd; size = 0; for (i = 0; i < gd->hsize; i++) { @@ -432,8 +433,10 @@ 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) + if ((cmd = get_proc_name(wp->fd, wp->tty)) != NULL) { format_add(ft, "pane_current_command", "%s", cmd); + free(cmd); + } format_add(ft, "cursor_x", "%d", wp->base.cx); format_add(ft, "cursor_y", "%d", wp->base.cy); -- cgit From 6fee3e9e4b4c68c5d3d7f333c779ac865af7bf86 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 25 Mar 2013 10:11:45 +0000 Subject: Rename session idx to session id throughout and add $ prefix to targets to use it, extended from a diff from George Nachman. --- format.c | 1 + 1 file changed, 1 insertion(+) (limited to 'format.c') diff --git a/format.c b/format.c index 11f003c8..dc988278 100644 --- a/format.c +++ b/format.c @@ -280,6 +280,7 @@ format_session(struct format_tree *ft, struct session *s) format_add(ft, "session_windows", "%u", winlink_count(&s->windows)); format_add(ft, "session_width", "%u", s->sx); format_add(ft, "session_height", "%u", s->sy); + format_add(ft, "session_id", "%u", s->id); sg = session_group_find(s); format_add(ft, "session_grouped", "%d", sg != NULL); -- cgit From 87fe1c0b0e47298de2cee7914d173cc18c4cd345 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 25 Mar 2013 11:40:54 +0000 Subject: Include prefix on ids, from George Nachman. --- format.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'format.c') diff --git a/format.c b/format.c index dc988278..b357876e 100644 --- a/format.c +++ b/format.c @@ -280,7 +280,7 @@ format_session(struct format_tree *ft, struct session *s) format_add(ft, "session_windows", "%u", winlink_count(&s->windows)); format_add(ft, "session_width", "%u", s->sx); format_add(ft, "session_height", "%u", s->sy); - format_add(ft, "session_id", "%u", s->id); + format_add(ft, "session_id", "$%u", s->id); sg = session_group_find(s); format_add(ft, "session_grouped", "%d", sg != NULL); -- cgit