Sync OpenBSD patchset 1031:

Use format for display-message, based on a diff from George Nachman.
This commit is contained in:
Tiago Cunha 2012-03-03 09:14:21 +00:00
parent 82f4db0d10
commit e0d2221879
2 changed files with 32 additions and 14 deletions

View File

@ -30,8 +30,8 @@ int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_message_entry = { const struct cmd_entry cmd_display_message_entry = {
"display-message", "display", "display-message", "display",
"c:pt:", 0, 1, "c:pt:F:", 0, 1,
"[-p] [-c target-client] [-t target-pane] [message]", "[-p] [-c target-client] [-t target-pane] [-F format] [message]",
0, 0,
NULL, NULL,
NULL, NULL,
@ -48,26 +48,44 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_pane *wp; struct window_pane *wp;
const char *template; const char *template;
char *msg; char *msg;
struct format_tree *ft;
char out[BUFSIZ];
time_t t;
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL) if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
return (-1); return (-1);
if (args_has(args, 't') != 0) { if (args_has(args, 't')) {
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
if (wl == NULL) if (wl == NULL)
return (-1); return (-1);
} else { } else {
s = NULL; wl = cmd_find_pane(ctx, NULL, &s, &wp);
wl = NULL; if (wl == NULL)
wp = NULL; return (-1);
} }
if (args->argc == 0) if (args_has(args, 'F') && args->argc != 0) {
template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)"; ctx->error(ctx, "only one of -F or argument must be given");
else return (-1);
template = args->argv[0]; }
msg = status_replace(c, s, wl, wp, template, time(NULL), 0); 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 = format_expand(ft, out);
if (args_has(self->args, 'p')) if (args_has(self->args, 'p'))
ctx->print(ctx, "%s", msg); ctx->print(ctx, "%s", msg);
else else

6
tmux.1
View File

@ -2994,9 +2994,9 @@ is given, the output is printed to stdout, otherwise it is displayed in the
status line. status line.
The format of The format of
.Ar message .Ar message
is as for is described in the
.Ic status-left , .Sx FORMATS
with the exception that #() are not handled; information is taken from section; information is taken from
.Ar target-pane .Ar target-pane
if if
.Fl t .Fl t