From ae7dda10ceaf340fdeb4b365b79ca77789ebd844 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Fri, 17 Jul 2009 18:32:54 +0000 Subject: [PATCH] - New command display-message (alias display) to display a message in the status line (bound to "i" by default). - Add support for including the window index, pane index, and window name in status-left, or status-right. - Bump protocol version. --- TODO | 1 - cmd-display-message.c | 65 +++++++++++++++++++++++++++++++++++++++++++ cmd.c | 3 +- examples/tmux.vim | 3 +- key-bindings.c | 3 +- status.c | 23 +++++++++++++-- tmux.1 | 14 +++++++++- tmux.h | 7 +++-- window.c | 17 ++++++++++- 9 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 cmd-display-message.c diff --git a/TODO b/TODO index ad237b04..5aac33fc 100644 --- a/TODO +++ b/TODO @@ -97,7 +97,6 @@ - is utf8 a valid charset in LANG? also check for "unicode" in TERM - what about utmp etc? can tmux update it like screen? setgid? - option to show bells visually -- window-status command to show current window info in status line - H/M/L commands in copy mode with vi-keys, for jumping to the top/middle/last line on the screen - if the server is started with IDENTIFY_UTF8 then set the global utf8 option? - I think there are potential leaks in the prompt code if a new prompt is created without the diff --git a/cmd-display-message.c b/cmd-display-message.c new file mode 100644 index 00000000..ddc9cb31 --- /dev/null +++ b/cmd-display-message.c @@ -0,0 +1,65 @@ +/* $Id: cmd-display-message.c,v 1.1 2009-07-17 18:32:54 tcunha Exp $ */ + +/* + * Copyright (c) 2009 Tiago Cunha + * + * 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 + +#include + +#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/cmd.c b/cmd.c index 633a0e91..1d689e81 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.104 2009-07-17 15:56:46 nicm Exp $ */ +/* $Id: cmd.c,v 1.105 2009-07-17 18:32:54 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/examples/tmux.vim b/examples/tmux.vim index 145fc068..6c2b04aa 100644 --- a/examples/tmux.vim +++ b/examples/tmux.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: tmux(1) configuration file " Maintainer: Tiago Cunha -" Last Change: $Date: 2009-07-13 18:29:28 $ +" Last Change: $Date: 2009-07-17 18:32:54 $ if version < 600 syntax clear @@ -37,6 +37,7 @@ syn keyword tmuxCmds choose-window loadb load-buffer copyb copy-buffer suspendc syn keyword tmuxCmds suspend-client findw find-window breakp break-pane nextl syn keyword tmuxCmds next-layout rotatew rotate-window confirm[-before] syn keyword tmuxCmds clearhist clear-history selectl select-layout if[-shell] +syn keyword tmuxCmds display[-message] syn keyword tmuxOptsSet prefix status status-fg status-bg bell-action syn keyword tmuxOptsSet default-command history-limit status-left status-right diff --git a/key-bindings.c b/key-bindings.c index a9c7a185..2ac62660 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -1,4 +1,4 @@ -/* $Id: key-bindings.c,v 1.74 2009-07-15 17:50:11 nicm Exp $ */ +/* $Id: key-bindings.c,v 1.75 2009-07-17 18:32:54 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/status.c b/status.c index a7b112fb..1b8e5a0b 100644 --- a/status.c +++ b/status.c @@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.97 2009-07-17 09:26:21 nicm Exp $ */ +/* $Id: status.c,v 1.98 2009-07-17 18:32:54 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/tmux.1 b/tmux.1 index c8de6f1e..5dc270f0 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.117 2009-07-17 07:45:42 nicm Exp $ +.\" $Id: tmux.1,v 1.118 2009-07-17 18:32:54 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -703,6 +703,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 @@ -1248,8 +1257,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/tmux.h b/tmux.h index 85470ab0..55c6fcd9 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.368 2009-07-17 12:12:54 nicm Exp $ */ +/* $Id: tmux.h,v 1.369 2009-07-17 18:32:54 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -21,7 +21,7 @@ #include "config.h" -#define PROTOCOL_VERSION -13 +#define PROTOCOL_VERSION -14 #include #include @@ -1099,6 +1099,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; @@ -1275,6 +1276,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 *); @@ -1436,6 +1438,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/window.c b/window.c index e290d8be..63aae9a1 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.93 2009-07-15 17:45:09 nicm Exp $ */ +/* $Id: window.c,v 1.94 2009-07-17 18:32:54 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -377,6 +377,21 @@ window_pane_at_index(struct window *w, u_int idx) return (NULL); } +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) {