summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-07-17 18:45:09 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-07-17 18:45:09 +0000
commit3bec6b49361c2d310a31ebd665752ca9a5fb1c67 (patch)
tree00bdf94785c82869c28ac46ae2b5b710e3b2c294 /usr.bin
parent37196951ad1e8aec5d3094bb38e36f52ee0ac565 (diff)
- New command display-message (alias display) to display a message in the
status line (bound to "i" and displays the current window and time by default). The same substitutions are applied as for status-left/right. - Add support for including the window index (#I), pane index (#P) and window name (#W) in the message, and status-left or status-right. - Bump protocol version. From Tiago Cunha, thanks!
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/Makefile5
-rw-r--r--usr.bin/tmux/cmd-display-message.c65
-rw-r--r--usr.bin/tmux/cmd.c3
-rw-r--r--usr.bin/tmux/key-bindings.c3
-rw-r--r--usr.bin/tmux/status.c23
-rw-r--r--usr.bin/tmux/tmux.114
-rw-r--r--usr.bin/tmux/tmux.h7
-rw-r--r--usr.bin/tmux/window.c17
8 files changed, 126 insertions, 11 deletions
diff --git a/usr.bin/tmux/Makefile b/usr.bin/tmux/Makefile
index 252d6d1b56f..7411d963c53 100644
--- a/usr.bin/tmux/Makefile
+++ b/usr.bin/tmux/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2009/07/14 06:30:45 nicm Exp $
+# $OpenBSD: Makefile,v 1.8 2009/07/17 18:45:08 nicm Exp $
PROG= tmux
SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
@@ -25,7 +25,8 @@ SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
cmd-split-window.c cmd-start-server.c cmd-string.c cmd-if-shell.c \
cmd-suspend-client.c cmd-swap-pane.c cmd-swap-window.c \
cmd-switch-client.c cmd-unbind-key.c cmd-unlink-window.c \
- cmd-up-pane.c cmd.c colour.c grid-view.c grid.c input-keys.c \
+ cmd-up-pane.c cmd-display-message.c cmd.c \
+ colour.c grid-view.c grid.c input-keys.c \
input.c key-bindings.c key-string.c layout-manual.c layout.c log.c \
mode-key.c names.c options-cmd.c options.c paste.c procname.c \
resize.c screen-redraw.c screen-write.c screen.c server-fn.c \
diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c
new file mode 100644
index 00000000000..dea7bf0748c
--- /dev/null
+++ b/usr.bin/tmux/cmd-display-message.c
@@ -0,0 +1,65 @@
+/* $OpenBSD: cmd-display-message.c,v 1.1 2009/07/17 18:45:08 nicm Exp $ */
+
+/*
+ * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <time.h>
+
+#include "tmux.h"
+
+/*
+ * Displays a message in the status line.
+ */
+
+int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_display_message_entry = {
+ "display-message", "display",
+ CMD_TARGET_CLIENT_USAGE " [message]",
+ CMD_ARG01, 0,
+ cmd_target_init,
+ cmd_target_parse,
+ cmd_display_message_exec,
+ cmd_target_send,
+ cmd_target_recv,
+ cmd_target_free,
+ cmd_target_print
+};
+
+int
+cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_target_data *data = self->data;
+ struct client *c;
+ const char *template;
+ char *msg;
+
+ if ((c = cmd_find_client(ctx, data->target)) == NULL)
+ return (-1);
+
+ if (data->arg == NULL)
+ template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)";
+ else
+ template = data->arg;
+
+ msg = status_replace(c->session, template, time(NULL));
+ status_message_set(c, "%s", msg);
+ xfree(msg);
+
+ return (0);
+}
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 0e2cb44fd80..f7728ca6941 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.6 2009/07/15 15:09:17 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.7 2009/07/17 18:45:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -41,6 +41,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_copy_mode_entry,
&cmd_delete_buffer_entry,
&cmd_detach_client_entry,
+ &cmd_display_message_entry,
&cmd_down_pane_entry,
&cmd_find_window_entry,
&cmd_has_session_entry,
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index 7633bbcae1c..e5e66077cbb 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.4 2009/07/17 13:43:07 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.5 2009/07/17 18:45:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -119,6 +119,7 @@ key_bindings_init(void)
{ 'c', 0, &cmd_new_window_entry },
{ 'd', 0, &cmd_detach_client_entry },
{ 'f', 0, &cmd_command_prompt_entry },
+ { 'i', 0, &cmd_display_message_entry },
{ 'l', 0, &cmd_last_window_entry },
{ 'n', 0, &cmd_next_window_entry },
{ 'o', 0, &cmd_down_pane_entry },
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index ca9bbd482ae..166748aad3a 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.12 2009/07/17 06:13:27 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.13 2009/07/17 18:45:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,6 @@
#include "tmux.h"
-char *status_replace(struct session *, char *, time_t);
char *status_replace_popen(char **);
size_t status_width(struct winlink *);
char *status_print(struct session *, struct winlink *, struct grid_cell *);
@@ -275,7 +274,7 @@ out:
}
char *
-status_replace(struct session *s, char *fmt, time_t t)
+status_replace(struct session *s, const char *fmt, time_t t)
{
struct winlink *wl = s->curw;
static char out[BUFSIZ];
@@ -323,6 +322,20 @@ status_replace(struct session *s, char *fmt, time_t t)
ptr = tmp;
}
/* FALLTHROUGH */
+ case 'I':
+ if (ptr == NULL) {
+ xsnprintf(tmp, sizeof tmp, "%d", wl->idx);
+ ptr = tmp;
+ }
+ /* FALLTHROUGH */
+ case 'P':
+ if (ptr == NULL) {
+ xsnprintf(tmp, sizeof tmp, "%u",
+ window_pane_index(wl->window,
+ wl->window->active));
+ ptr = tmp;
+ }
+ /* FALLTHOUGH */
case 'S':
if (ptr == NULL)
ptr = s->name;
@@ -330,6 +343,10 @@ status_replace(struct session *s, char *fmt, time_t t)
case 'T':
if (ptr == NULL)
ptr = wl->window->active->base.title;
+ /* FALLTHROUGH */
+ case 'W':
+ if (ptr == NULL)
+ ptr = wl->window->name;
len = strlen(ptr);
if ((size_t) n < len)
len = n;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index c114559387c..9ced913da4b 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.34 2009/07/17 15:03:11 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.35 2009/07/17 18:45:08 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -717,6 +717,15 @@ or the top buffer if not specified.
.D1 (alias: Ic detach )
Detach the current client if bound to a key, or the specified client with
.Fl t .
+.It Xo Ic display-message
+.Op Fl t Ar target-client
+.Op Ar message
+.Xc
+.D1 (alias: Ic display )
+Display a message (see the
+.Ic status-left
+option below)
+in the status line.
.It Xo Ic down-pane
.Op Fl p Ar pane-index
.Op Fl t Ar target-window
@@ -1262,8 +1271,11 @@ may contain any of the following special character pairs:
.It Sy "Character pair" Ta Sy "Replaced with"
.It Li "#(command)" Ta "First line of command's output"
.It Li "#H" Ta "Hostname of local host"
+.It Li "#I" Ta "Current window index"
+.It Li "#P" Ta "Current pane index"
.It Li "#S" Ta "Session name"
.It Li "#T" Ta "Current window title"
+.It Li "#W" Ta "Current window name"
.It Li "##" Ta "A literal" Ql #
.El
.Pp
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 70f423d7cf3..ed504446be7 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.35 2009/07/17 15:03:11 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.36 2009/07/17 18:45:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -19,7 +19,7 @@
#ifndef TMUX_H
#define TMUX_H
-#define PROTOCOL_VERSION -13
+#define PROTOCOL_VERSION -14
#include <sys/param.h>
#include <sys/time.h>
@@ -1110,6 +1110,7 @@ extern const struct cmd_entry cmd_copy_buffer_entry;
extern const struct cmd_entry cmd_copy_mode_entry;
extern const struct cmd_entry cmd_delete_buffer_entry;
extern const struct cmd_entry cmd_detach_client_entry;
+extern const struct cmd_entry cmd_display_message_entry;
extern const struct cmd_entry cmd_down_pane_entry;
extern const struct cmd_entry cmd_find_window_entry;
extern const struct cmd_entry cmd_has_session_entry;
@@ -1286,6 +1287,7 @@ int server_unlock(const char *);
/* status.c */
int status_redraw(struct client *);
+char *status_replace(struct session *, const char *, time_t);
void printflike2 status_message_set(struct client *, const char *, ...);
void status_message_clear(struct client *);
int status_message_redraw(struct client *);
@@ -1447,6 +1449,7 @@ struct window_pane *window_add_pane(struct window *, int,
const char *, const char *, const char **, u_int, char **);
void window_remove_pane(struct window *, struct window_pane *);
struct window_pane *window_pane_at_index(struct window *, u_int);
+u_int window_pane_index(struct window *, struct window_pane *);
u_int window_count_panes(struct window *);
void window_destroy_panes(struct window *);
struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 2b9afef3a5d..f4f60fc6f57 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.12 2009/07/15 08:00:49 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.13 2009/07/17 18:45:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -380,6 +380,21 @@ window_pane_at_index(struct window *w, u_int idx)
}
u_int
+window_pane_index(struct window *w, struct window_pane *wp)
+{
+ struct window_pane *wq;
+ u_int n;
+
+ n = 0;
+ TAILQ_FOREACH(wq, &w->panes, entry) {
+ if (wp == wq)
+ break;
+ n++;
+ }
+ return (n);
+}
+
+u_int
window_count_panes(struct window *w)
{
struct window_pane *wp;