Merge branch 'obsd-master'

pull/3573/head
Thomas Adam 2023-04-28 12:52:21 +01:00
commit fbe6fe7f55
3 changed files with 60 additions and 23 deletions

View File

@ -41,8 +41,9 @@ const struct cmd_entry cmd_confirm_before_entry = {
.name = "confirm-before", .name = "confirm-before",
.alias = "confirm", .alias = "confirm",
.args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse }, .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
.usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command", .usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
" command",
.flags = CMD_CLIENT_TFLAG, .flags = CMD_CLIENT_TFLAG,
.exec = cmd_confirm_before_exec .exec = cmd_confirm_before_exec
@ -51,6 +52,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
struct cmd_confirm_before_data { struct cmd_confirm_before_data {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
u_char confirm_key;
int default_yes;
}; };
static enum args_parse_type static enum args_parse_type
@ -68,7 +71,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
char *new_prompt; char *new_prompt;
const char *prompt, *cmd; const char *confirm_key, *prompt, *cmd;
int wait = !args_has(args, 'b'); int wait = !args_has(args, 'b');
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
@ -79,11 +82,26 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
if (wait) if (wait)
cdata->item = item; cdata->item = item;
cdata->default_yes = args_has(args, 'y');
if ((confirm_key = args_get(args, 'c')) != NULL) {
if (confirm_key[1] == '\0' &&
confirm_key[0] > 31 &&
confirm_key[0] < 127)
cdata->confirm_key = confirm_key[0];
else {
cmdq_error(item, "invalid confirm key");
return (CMD_RETURN_ERROR);
}
}
else
cdata->confirm_key = 'y';
if ((prompt = args_get(args, 'p')) != NULL) if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt); xasprintf(&new_prompt, "%s ", prompt);
else { else {
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name; cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd); xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
cmd, cdata->confirm_key);
} }
status_prompt_set(tc, target, new_prompt, NULL, status_prompt_set(tc, target, new_prompt, NULL,
@ -107,9 +125,9 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
if (c->flags & CLIENT_DEAD) if (c->flags & CLIENT_DEAD)
goto out; goto out;
if (s == NULL || *s == '\0') if (s == NULL)
goto out; goto out;
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0') if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes))
goto out; goto out;
retcode = 0; retcode = 0;
@ -123,12 +141,12 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
} }
out: out:
if (item != NULL) { if (item != NULL) {
if (cmdq_get_client(item) != NULL && if (cmdq_get_client(item) != NULL &&
cmdq_get_client(item)->session == NULL) cmdq_get_client(item)->session == NULL)
cmdq_get_client(item)->retval = retcode; cmdq_get_client(item)->retval = retcode;
cmdq_continue(item); cmdq_continue(item);
} }
return (0); return (0);
} }

11
tmux.1
View File

@ -5810,7 +5810,8 @@ the prompt is shown in the background and the invoking client does not exit
until it is dismissed. until it is dismissed.
.Tg confirm .Tg confirm
.It Xo Ic confirm-before .It Xo Ic confirm-before
.Op Fl b .Op Fl by
.Op Fl c Ar confirm-key
.Op Fl p Ar prompt .Op Fl p Ar prompt
.Op Fl t Ar target-client .Op Fl t Ar target-client
.Ar command .Ar command
@ -5831,6 +5832,14 @@ With
.Fl b , .Fl b ,
the prompt is shown in the background and the invoking client does not exit the prompt is shown in the background and the invoking client does not exit
until it is dismissed. until it is dismissed.
.Fl y
changes the default behaviour (if Enter alone is pressed) of the prompt to
run the command.
.Fl c
changes the confirmation key to
.Ar confirm-key ;
the default is
.Ql y .
.Tg menu .Tg menu
.It Xo Ic display-menu .It Xo Ic display-menu
.Op Fl O .Op Fl O

View File

@ -777,8 +777,10 @@ tty_term_string_i(struct tty_term *term, enum tty_code_code code, int a)
#else #else
s = tparm((char *)x, a, 0, 0, 0, 0, 0, 0, 0, 0); s = tparm((char *)x, a, 0, 0, 0, 0, 0, 0, 0, 0);
#endif #endif
if (s == NULL) if (s == NULL) {
fatalx("could not expand %s", tty_term_codes[code].name); log_debug("could not expand %s", tty_term_codes[code].name);
return ("");
}
return (s); return (s);
} }
@ -794,8 +796,10 @@ tty_term_string_ii(struct tty_term *term, enum tty_code_code code, int a, int b)
#else #else
s = tparm((char *)x, a, b, 0, 0, 0, 0, 0, 0, 0); s = tparm((char *)x, a, b, 0, 0, 0, 0, 0, 0, 0);
#endif #endif
if (s == NULL) if (s == NULL) {
fatalx("could not expand %s", tty_term_codes[code].name); log_debug("could not expand %s", tty_term_codes[code].name);
return ("");
}
return (s); return (s);
} }
@ -812,8 +816,10 @@ tty_term_string_iii(struct tty_term *term, enum tty_code_code code, int a,
#else #else
s = tparm((char *)x, a, b, c, 0, 0, 0, 0, 0, 0); s = tparm((char *)x, a, b, c, 0, 0, 0, 0, 0, 0);
#endif #endif
if (s == NULL) if (s == NULL) {
fatalx("could not expand %s", tty_term_codes[code].name); log_debug("could not expand %s", tty_term_codes[code].name);
return ("");
}
return (s); return (s);
} }
@ -829,8 +835,10 @@ tty_term_string_s(struct tty_term *term, enum tty_code_code code, const char *a)
#else #else
s = tparm((char *)x, (long)a, 0, 0, 0, 0, 0, 0, 0, 0); s = tparm((char *)x, (long)a, 0, 0, 0, 0, 0, 0, 0, 0);
#endif #endif
if (s == NULL) if (s == NULL) {
fatalx("could not expand %s", tty_term_codes[code].name); log_debug("could not expand %s", tty_term_codes[code].name);
return ("");
}
return (s); return (s);
} }
@ -847,8 +855,10 @@ tty_term_string_ss(struct tty_term *term, enum tty_code_code code,
#else #else
s = tparm((char *)x, (long)a, (long)b, 0, 0, 0, 0, 0, 0, 0); s = tparm((char *)x, (long)a, (long)b, 0, 0, 0, 0, 0, 0, 0);
#endif #endif
if (s == NULL) if (s == NULL) {
fatalx("could not expand %s", tty_term_codes[code].name); log_debug("could not expand %s", tty_term_codes[code].name);
return ("");
}
return (s); return (s);
} }