diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-02-23 22:40:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-02-23 22:40:59 +0000 |
commit | 6428e8f7531a5d373ba3bbcdfb996d324c777976 (patch) | |
tree | 0288d762c9d5245dbf343132110cc865975f3f82 /usr.bin | |
parent | fb47d5e42efc0737d910b8ac0af506513f19de4a (diff) |
Use format for display-message, based on a diff from George Nachman.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-display-message.c | 40 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 10 |
2 files changed, 34 insertions, 16 deletions
diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c index 03de7d1e0cf..352a31e1304 100644 --- a/usr.bin/tmux/cmd-display-message.c +++ b/usr.bin/tmux/cmd-display-message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-message.c,v 1.10 2011/04/06 11:36:26 miod Exp $ */ +/* $OpenBSD: cmd-display-message.c,v 1.11 2012/02/23 22:40:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -30,8 +30,8 @@ int cmd_display_message_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_display_message_entry = { "display-message", "display", - "c:pt:", 0, 1, - "[-p] [-c target-client] [-t target-pane] [message]", + "c:pt:F:", 0, 1, + "[-p] [-c target-client] [-t target-pane] [-F format] [message]", 0, NULL, NULL, @@ -48,26 +48,44 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) struct window_pane *wp; const char *template; char *msg; + struct format_tree *ft; + char out[BUFSIZ]; + time_t t; if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) return (-1); - if (args_has(args, 't') != 0) { + if (args_has(args, 't')) { wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); if (wl == NULL) return (-1); } else { - s = NULL; - wl = NULL; - wp = NULL; + wl = cmd_find_pane(ctx, NULL, &s, &wp); + if (wl == NULL) + return (-1); } - if (args->argc == 0) - template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)"; - else + if (args_has(args, 'F') && args->argc != 0) { + ctx->error(ctx, "only one of -F or argument must be given"); + return (-1); + } + + template = args_get(args, 'F'); + if (args->argc != 0) template = args->argv[0]; + if (template == NULL) + template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)"; + + ft = format_create(); + format_client(ft, c); + format_session(ft, s); + format_winlink(ft, s, wl); + format_window_pane(ft, wp); + + t = time(NULL); + strftime(out, sizeof out, template, localtime(&t)); - msg = status_replace(c, s, wl, wp, template, time(NULL), 0); + msg = format_expand(ft, out); if (args_has(self->args, 'p')) ctx->print(ctx, "%s", msg); else diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 8074a925f02..e2925138603 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.274 2012/02/02 22:33:05 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.275 2012/02/23 22:40:58 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -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: February 2 2012 $ +.Dd $Mdocdate: February 23 2012 $ .Dt TMUX 1 .Os .Sh NAME @@ -2990,9 +2990,9 @@ is given, the output is printed to stdout, otherwise it is displayed in the status line. The format of .Ar message -is as for -.Ic status-left , -with the exception that #() are not handled; information is taken from +is described in the +.Sx FORMATS +section; information is taken from .Ar target-pane if .Fl t |