summaryrefslogtreecommitdiffstats
path: root/cmd-display-message.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-02-23 22:40:58 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-02-23 22:40:58 +0000
commitaaf0bfccf45b2c2a606ef104b620939a5abcbddc (patch)
tree0e0bdb31685b1efae749c6ac7e9549f1a3431542 /cmd-display-message.c
parentfe055c89f524bf50439ec7bcbc29ae363bf6e6ae (diff)
Use format for display-message, based on a diff from George Nachman.
Diffstat (limited to 'cmd-display-message.c')
-rw-r--r--cmd-display-message.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/cmd-display-message.c b/cmd-display-message.c
index b2cf832b..fb650501 100644
--- a/cmd-display-message.c
+++ b/cmd-display-message.c
@@ -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