summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-06-16 10:55:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-06-16 10:55:48 +0000
commit0e8512c7f78581c5b800d6579e0ac7e96b62c258 (patch)
tree1b5b127f0a5ef3eb3f505e1d88a7a2444f970823
parent1934a65b6319ccf2c18490f5f974c6aae62d41a7 (diff)
Allow a command to be specified to display-panes, similar to
command-prompt, rather than always just selecting the pane.
-rw-r--r--usr.bin/tmux/cmd-display-panes.c61
-rw-r--r--usr.bin/tmux/server-client.c11
-rw-r--r--usr.bin/tmux/server-fn.c22
-rw-r--r--usr.bin/tmux/tmux.121
-rw-r--r--usr.bin/tmux/tmux.h6
-rw-r--r--usr.bin/tmux/window.c3
6 files changed, 95 insertions, 29 deletions
diff --git a/usr.bin/tmux/cmd-display-panes.c b/usr.bin/tmux/cmd-display-panes.c
index fcd758f6ef1..731540578d1 100644
--- a/usr.bin/tmux/cmd-display-panes.c
+++ b/usr.bin/tmux/cmd-display-panes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-display-panes.c,v 1.12 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: cmd-display-panes.c,v 1.13 2016/06/16 10:55:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -18,19 +18,25 @@
#include <sys/types.h>
+#include <ctype.h>
+#include <stdlib.h>
+
#include "tmux.h"
/*
* Display panes on a client.
*/
-enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
+static enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
+
+static void cmd_display_panes_callback(struct client *,
+ struct window_pane *);
const struct cmd_entry cmd_display_panes_entry = {
.name = "display-panes",
.alias = "displayp",
- .args = { "t:", 0, 0 },
+ .args = { "t:", 0, 1 },
.usage = CMD_TARGET_CLIENT_USAGE,
.tflag = CMD_CLIENT,
@@ -39,10 +45,53 @@ const struct cmd_entry cmd_display_panes_entry = {
.exec = cmd_display_panes_exec
};
-enum cmd_retval
-cmd_display_panes_exec(__unused struct cmd *self, struct cmd_q *cmdq)
+static enum cmd_retval
+cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
{
- server_set_identify(cmdq->state.c);
+ struct args *args = self->args;
+ struct client *c = cmdq->state.c;
+
+ if (c->identify_callback != NULL)
+ return (CMD_RETURN_NORMAL);
+
+ c->identify_callback = cmd_display_panes_callback;
+ if (args->argc != 0)
+ c->identify_callback_data = xstrdup(args->argv[0]);
+ else
+ c->identify_callback_data = xstrdup("select-pane -t '%%'");
+
+ server_set_identify(c);
return (CMD_RETURN_NORMAL);
}
+
+static void
+cmd_display_panes_callback(struct client *c, struct window_pane *wp)
+{
+ struct cmd_list *cmdlist;
+ char *template, *cmd, *expanded, *cause;
+
+ template = c->identify_callback_data;
+ if (wp != NULL) {
+ xasprintf(&expanded, "%%%u", wp->id);
+ cmd = cmd_template_replace(template, expanded, 1);
+
+ if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
+ if (cause != NULL) {
+ *cause = toupper((u_char) *cause);
+ status_message_set(c, "%s", cause);
+ free(cause);
+ }
+ } else {
+ cmdq_run(c->cmdq, cmdlist, NULL);
+ cmd_list_free(cmdlist);
+ }
+
+ free(cmd);
+ free(expanded);
+ }
+
+ free(c->identify_callback_data);
+ c->identify_callback_data = NULL;
+ c->identify_callback = NULL;
+}
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 5f744ba1c79..e71b62682ba 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.186 2016/04/30 18:59:02 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.187 2016/06/16 10:55:47 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -184,6 +184,7 @@ server_client_lost(struct client *c)
c->flags |= CLIENT_DEAD;
+ server_clear_identify(c, NULL);
status_prompt_clear(c);
status_message_clear(c);
@@ -606,16 +607,16 @@ server_client_handle_key(struct client *c, key_code key)
return;
window_unzoom(w);
wp = window_pane_at_index(w, key - '0');
- if (wp != NULL && window_pane_visible(wp))
- window_set_active_pane(w, wp);
- server_clear_identify(c);
+ if (wp != NULL && !window_pane_visible(wp))
+ wp = NULL;
+ server_clear_identify(c, wp);
return;
}
/* Handle status line. */
if (!(c->flags & CLIENT_READONLY)) {
status_message_clear(c);
- server_clear_identify(c);
+ server_clear_identify(c, NULL);
}
if (c->prompt_string != NULL) {
if (!(c->flags & CLIENT_READONLY))
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c
index c143f172999..58b3bbd655a 100644
--- a/usr.bin/tmux/server-fn.c
+++ b/usr.bin/tmux/server-fn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-fn.c,v 1.98 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.99 2016/06/16 10:55:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -441,21 +441,23 @@ server_set_identify(struct client *c)
}
void
-server_clear_identify(struct client *c)
+server_clear_identify(struct client *c, struct window_pane *wp)
{
- if (c->flags & CLIENT_IDENTIFY) {
- c->flags &= ~CLIENT_IDENTIFY;
- c->tty.flags &= ~(TTY_FREEZE|TTY_NOCURSOR);
- server_redraw_client(c);
- }
+ if (~c->flags & CLIENT_IDENTIFY)
+ return;
+ c->flags &= ~CLIENT_IDENTIFY;
+
+ if (c->identify_callback != NULL)
+ c->identify_callback(c, wp);
+
+ c->tty.flags &= ~(TTY_FREEZE|TTY_NOCURSOR);
+ server_redraw_client(c);
}
void
server_callback_identify(__unused int fd, __unused short events, void *data)
{
- struct client *c = data;
-
- server_clear_identify(c);
+ server_clear_identify(data, NULL);
}
/* Set stdin callback. */
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 1f2fa408786..b62583483c2 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.490 2016/06/15 14:43:06 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.491 2016/06/16 10:55:47 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: June 15 2016 $
+.Dd $Mdocdate: June 16 2016 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1458,7 +1458,11 @@ flag, see the
.Sx FORMATS
section.
This command works only if at least one client is attached.
-.It Ic display-panes Op Fl t Ar target-client
+.It Xo
+.Ic display-panes
+.Op Fl t Ar target-client
+.Op Ar template
+.Xc
.D1 (alias: Ic displayp )
Display a visible indicator of each pane shown by
.Ar target-client .
@@ -1468,11 +1472,18 @@ See the
and
.Ic display-panes-active-colour
session options.
-While the indicator is on screen, a pane may be selected with the
+While the indicator is on screen, a pane may be chosen with the
.Ql 0
to
.Ql 9
-keys.
+keys, which will cause
+.Ar template
+to be executed as a command with
+.Ql %%
+substituted by the pane ID.
+The default
+.Ar template
+is "select-pane -t '%%'".
.It Xo Ic find-window
.Op Fl CNT
.Op Fl F Ar format
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 569657c6fd3..795c6e370cf 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.635 2016/06/15 09:13:46 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.636 2016/06/16 10:55:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1277,6 +1277,8 @@ struct client {
struct key_table *keytable;
struct event identify_timer;
+ void (*identify_callback)(struct client *, struct window_pane *);
+ void *identify_callback_data;
char *message_string;
struct event message_timer;
@@ -1937,7 +1939,7 @@ void server_destroy_session_group(struct session *);
void server_destroy_session(struct session *);
void server_check_unattached(void);
void server_set_identify(struct client *);
-void server_clear_identify(struct client *);
+void server_clear_identify(struct client *, struct window_pane *);
int server_set_stdin_callback(struct client *, void (*)(struct client *,
int, void *), void *, char **);
void server_unzoom_window(struct window *);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 3ca19e2f27f..a248ced1d7d 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.162 2016/06/15 09:13:46 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.163 2016/06/16 10:55:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
#include <util.h>