aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-06-16 14:01:11 +0100
committerThomas Adam <thomas@xteddy.org>2016-06-16 14:01:11 +0100
commit93f42d360b8dbeff738992c15067d608ead16c21 (patch)
tree4f9cc77ac128f028a343bcc73651a8f12c61d099
parentd35a9ac5f20f65eecd1822e9a4ace2033756656a (diff)
parent325cbe90d925d3deb90559463b6d968c31fa5924 (diff)
downloadrtmux-93f42d360b8dbeff738992c15067d608ead16c21.tar.gz
rtmux-93f42d360b8dbeff738992c15067d608ead16c21.tar.bz2
rtmux-93f42d360b8dbeff738992c15067d608ead16c21.zip
Merge branch 'obsd-master'
-rw-r--r--cmd-display-panes.c59
-rw-r--r--server-client.c9
-rw-r--r--server-fn.c20
-rw-r--r--tmux.117
-rw-r--r--tmux.h4
-rw-r--r--window.c1
6 files changed, 88 insertions, 22 deletions
diff --git a/cmd-display-panes.c b/cmd-display-panes.c
index eed3611e..db85c813 100644
--- a/cmd-display-panes.c
+++ b/cmd-display-panes.c
@@ -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/server-client.c b/server-client.c
index 531d710c..f61cfa38 100644
--- a/server-client.c
+++ b/server-client.c
@@ -182,6 +182,7 @@ server_client_lost(struct client *c)
c->flags |= CLIENT_DEAD;
+ server_clear_identify(c, NULL);
status_prompt_clear(c);
status_message_clear(c);
@@ -604,16 +605,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/server-fn.c b/server-fn.c
index 78bc2bea..53d6a7c2 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -442,21 +442,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/tmux.1 b/tmux.1
index 7fdf91c4..b4f18ec8 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1462,7 +1462,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 .
@@ -1472,11 +1476,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/tmux.h b/tmux.h
index a596de21..9f5e6310 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1279,6 +1279,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;
@@ -1939,7 +1941,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/window.c b/window.c
index 44927138..20c7861f 100644
--- a/window.c
+++ b/window.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
#include <time.h>