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