2009-07-17 18:45:08 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
#include <stdlib.h>
|
2009-07-17 18:45:08 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Displays a message in the status line.
|
|
|
|
*/
|
|
|
|
|
2014-10-20 23:35:28 +00:00
|
|
|
#define DISPLAY_MESSAGE_TEMPLATE \
|
|
|
|
"[#{session_name}] #{window_index}:" \
|
|
|
|
"#{window_name}, current pane #{pane_index} " \
|
|
|
|
"- (%H:%M %d-%b-%y)"
|
|
|
|
|
2013-03-24 09:54:10 +00:00
|
|
|
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
|
2009-07-17 18:45:08 +00:00
|
|
|
|
|
|
|
const struct cmd_entry cmd_display_message_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "display-message",
|
|
|
|
.alias = "display",
|
|
|
|
|
|
|
|
.args = { "c:pt:F:", 0, 1 },
|
|
|
|
.usage = "[-p] [-c target-client] [-F format] "
|
|
|
|
CMD_TARGET_PANE_USAGE " [message]",
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.cflag = CMD_CLIENT_CANFAIL,
|
|
|
|
.tflag = CMD_PANE,
|
|
|
|
|
|
|
|
.flags = 0,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_display_message_exec
|
2009-07-17 18:45:08 +00:00
|
|
|
};
|
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
enum cmd_retval
|
2013-03-24 09:54:10 +00:00
|
|
|
cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
|
2009-07-17 18:45:08 +00:00
|
|
|
{
|
2011-01-04 00:42:46 +00:00
|
|
|
struct args *args = self->args;
|
2015-12-13 14:32:38 +00:00
|
|
|
struct client *c = cmdq->state.c;
|
|
|
|
struct session *s = cmdq->state.tflag.s;
|
|
|
|
struct winlink *wl = cmdq->state.tflag.wl;
|
|
|
|
struct window_pane *wp = cmdq->state.tflag.wp;
|
2009-07-17 18:45:08 +00:00
|
|
|
const char *template;
|
|
|
|
char *msg;
|
2012-02-23 22:40:58 +00:00
|
|
|
struct format_tree *ft;
|
2009-07-17 18:45:08 +00:00
|
|
|
|
2012-02-23 22:40:58 +00:00
|
|
|
if (args_has(args, 'F') && args->argc != 0) {
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_error(cmdq, "only one of -F or argument must be given");
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-02-23 22:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template = args_get(args, 'F');
|
|
|
|
if (args->argc != 0)
|
2011-01-04 00:42:46 +00:00
|
|
|
template = args->argv[0];
|
2012-02-23 22:40:58 +00:00
|
|
|
if (template == NULL)
|
2012-08-14 08:51:53 +00:00
|
|
|
template = DISPLAY_MESSAGE_TEMPLATE;
|
2012-02-23 22:40:58 +00:00
|
|
|
|
2015-12-11 12:27:36 +00:00
|
|
|
ft = format_create(cmdq, 0);
|
2015-02-05 10:29:43 +00:00
|
|
|
format_defaults(ft, c, s, wl, wp);
|
2012-02-23 22:40:58 +00:00
|
|
|
|
2015-11-18 16:49:13 +00:00
|
|
|
msg = format_expand_time(ft, template, time(NULL));
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 'p'))
|
2013-03-24 09:54:10 +00:00
|
|
|
cmdq_print(cmdq, "%s", msg);
|
2009-11-24 19:16:11 +00:00
|
|
|
else
|
|
|
|
status_message_set(c, "%s", msg);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(msg);
|
2012-03-03 09:45:41 +00:00
|
|
|
format_free(ft);
|
2013-03-24 09:54:10 +00:00
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-07-17 18:45:08 +00:00
|
|
|
}
|