Add a -d option to display-message to set delay, from theonekeyg at

gmail dot com in GitHub issue 2322.
This commit is contained in:
nicm 2020-07-27 08:03:10 +00:00
parent d329b035ce
commit 40e65c5115
9 changed files with 39 additions and 16 deletions

View File

@ -316,9 +316,9 @@ alerts_set_message(struct winlink *wl, const char *type, const char *option)
if (visual == VISUAL_OFF)
continue;
if (c->session->curw == wl)
status_message_set(c, 1, "%s in current window", type);
status_message_set(c, -1, 1, "%s in current window", type);
else {
status_message_set(c, 1, "%s in window %d", type,
status_message_set(c, -1, 1, "%s in window %d", type,
wl->idx);
}
}

View File

@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
.name = "display-message",
.alias = "display",
.args = { "ac:Ipt:F:v", 0, 1 },
.usage = "[-aIpv] [-c target-client] [-F format] "
.args = { "acd:Ipt:F:v", 0, 1 },
.usage = "[-aIpv] [-c target-client] [-d delay] [-F format] "
CMD_TARGET_PANE_USAGE " [message]",
.target = { 't', CMD_FIND_PANE, 0 },
@ -68,6 +68,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
struct window_pane *wp = target->wp;
const char *template;
char *msg, *cause;
int delay = -1;
struct format_tree *ft;
int flags;
@ -85,6 +86,15 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'd')) {
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
if (cause != NULL) {
cmdq_error(item, "delay %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
template = args_get(args, 'F');
if (args->argc != 0)
template = args->argv[0];
@ -117,7 +127,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'p'))
cmdq_print(item, "%s", msg);
else if (tc != NULL)
status_message_set(tc, 0, "%s", msg);
status_message_set(tc, delay, 0, "%s", msg);
free(msg);
format_free(ft);

View File

@ -114,7 +114,7 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
note = xstrdup(bd->note);
tmp = utf8_padcstr(key, keywidth + 1);
if (args_has(args, '1') && tc != NULL)
status_message_set(tc, 1, "%s%s%s", prefix, tmp, note);
status_message_set(tc, -1, 1, "%s%s%s", prefix, tmp, note);
else
cmdq_print(item, "%s%s%s", prefix, tmp, note);
free(tmp);

View File

@ -858,7 +858,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
c->retval = 1;
} else {
*msg = toupper((u_char) *msg);
status_message_set(c, 1, "%s", msg);
status_message_set(c, -1, 1, "%s", msg);
}
free(msg);

View File

@ -1176,7 +1176,7 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
if (status == CMD_PARSE_ERROR) {
if (c != NULL) {
*error = toupper((u_char)*error);
status_message_set(c, 1, "%s", error);
status_message_set(c, -1, 1, "%s", error);
}
free(error);
}

View File

@ -423,11 +423,11 @@ status_redraw(struct client *c)
/* Set a status line message. */
void
status_message_set(struct client *c, int ignore_styles, const char *fmt, ...)
status_message_set(struct client *c, int delay, int ignore_styles,
const char *fmt, ...)
{
struct timeval tv;
va_list ap;
int delay;
status_message_clear(c);
status_push_screen(c);
@ -439,7 +439,12 @@ status_message_set(struct client *c, int ignore_styles, const char *fmt, ...)
server_add_message("%s message: %s", c->name, c->message_string);
delay = options_get_number(c->session->options, "display-time");
/*
* With delay -1, the display-time option is used; zero means wait for
* key press; more than zero is the actual delay time in milliseconds.
*/
if (delay == -1)
delay = options_get_number(c->session->options, "display-time");
if (delay > 0) {
tv.tv_sec = delay / 1000;
tv.tv_usec = (delay % 1000) * 1000L;
@ -447,6 +452,7 @@ status_message_set(struct client *c, int ignore_styles, const char *fmt, ...)
if (event_initialized(&c->message_timer))
evtimer_del(&c->message_timer);
evtimer_set(&c->message_timer, status_message_callback, c);
evtimer_add(&c->message_timer, &tv);
}

10
tmux.1
View File

@ -5378,6 +5378,7 @@ The following keys are also available:
.It Xo Ic display-message
.Op Fl aIpv
.Op Fl c Ar target-client
.Op Fl d Ar delay
.Op Fl t Ar target-pane
.Op Ar message
.Xc
@ -5387,7 +5388,14 @@ If
.Fl p
is given, the output is printed to stdout, otherwise it is displayed in the
.Ar target-client
status line.
status line for up to
.Ar delay
milliseconds.
If
.Ar delay
is not given, the
.Ic message-time
option is used; a delay of zero waits for a key press.
The format of
.Ar message
is described in the

3
tmux.h
View File

@ -2450,8 +2450,7 @@ struct style_range *status_get_range(struct client *, u_int, u_int);
void status_init(struct client *);
void status_free(struct client *);
int status_redraw(struct client *);
void printflike(3, 4) status_message_set(struct client *, int, const char *,
...);
void status_message_set(struct client *, int, int, const char *, ...);
void status_message_clear(struct client *);
int status_message_redraw(struct client *);
void status_prompt_set(struct client *, struct cmd_find_state *,

View File

@ -1003,7 +1003,7 @@ window_customize_set_option_callback(struct client *c, void *itemdata,
fail:
*cause = toupper((u_char)*cause);
status_message_set(c, 1, "%s", cause);
status_message_set(c, -1, 1, "%s", cause);
free(cause);
return (0);
}
@ -1209,7 +1209,7 @@ window_customize_set_command_callback(struct client *c, void *itemdata,
fail:
*error = toupper((u_char)*error);
status_message_set(c, 1, "%s", error);
status_message_set(c, -1, 1, "%s", error);
free(error);
return (0);
}