From bf636d9575806134ca7efd917ee0d54e9330ae86 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 28 Apr 2023 05:59:35 +0000 Subject: [PATCH 1/2] Do not fatal if tparm fails, instead just log it (not working sequences are better than exiting). --- tty-term.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/tty-term.c b/tty-term.c index 94d2f66c..9b897c67 100644 --- a/tty-term.c +++ b/tty-term.c @@ -759,8 +759,10 @@ tty_term_string_i(struct tty_term *term, enum tty_code_code code, int a) const char *x = tty_term_string(term, code), *s; s = tparm((char *)x, a); - if (s == NULL) - fatalx("could not expand %s", tty_term_codes[code].name); + if (s == NULL) { + log_debug("could not expand %s", tty_term_codes[code].name); + return (""); + } return (s); } @@ -770,20 +772,24 @@ tty_term_string_ii(struct tty_term *term, enum tty_code_code code, int a, int b) const char *x = tty_term_string(term, code), *s; s = tparm((char *)x, a, b); - if (s == NULL) - fatalx("could not expand %s", tty_term_codes[code].name); + if (s == NULL) { + log_debug("could not expand %s", tty_term_codes[code].name); + return (""); + } return (s); } const char * -tty_term_string_iii(struct tty_term *term, enum tty_code_code code, int a, int b, - int c) +tty_term_string_iii(struct tty_term *term, enum tty_code_code code, int a, + int b, int c) { const char *x = tty_term_string(term, code), *s; s = tparm((char *)x, a, b, c); - if (s == NULL) - fatalx("could not expand %s", tty_term_codes[code].name); + if (s == NULL) { + log_debug("could not expand %s", tty_term_codes[code].name); + return (""); + } return (s); } @@ -793,20 +799,24 @@ tty_term_string_s(struct tty_term *term, enum tty_code_code code, const char *a) const char *x = tty_term_string(term, code), *s; s = tparm((char *)x, (long)a); - if (s == NULL) - fatalx("could not expand %s", tty_term_codes[code].name); + if (s == NULL) { + log_debug("could not expand %s", tty_term_codes[code].name); + return (""); + } return (s); } const char * -tty_term_string_ss(struct tty_term *term, enum tty_code_code code, const char *a, - const char *b) +tty_term_string_ss(struct tty_term *term, enum tty_code_code code, + const char *a, const char *b) { const char *x = tty_term_string(term, code), *s; s = tparm((char *)x, (long)a, (long)b); - if (s == NULL) - fatalx("could not expand %s", tty_term_codes[code].name); + if (s == NULL) { + log_debug("could not expand %s", tty_term_codes[code].name); + return (""); + } return (s); } From 41b318ac7c881fc4cdf834ea5e14a7e8646605aa Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 28 Apr 2023 06:12:27 +0000 Subject: [PATCH 2/2] Add options to change the confirm key and default behaviour of confirm-before. From Elias Assaf in GitHub issue 3548; prompted by an earlier change from Yutaro Yoshii in GitHub issue 3496. --- cmd-confirm-before.c | 42 ++++++++++++++++++++++++++++++------------ tmux.1 | 11 ++++++++++- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index ce8c95e0..485e6e65 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -41,8 +41,9 @@ const struct cmd_entry cmd_confirm_before_entry = { .name = "confirm-before", .alias = "confirm", - .args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse }, - .usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command", + .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse }, + .usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE + " command", .flags = CMD_CLIENT_TFLAG, .exec = cmd_confirm_before_exec @@ -51,6 +52,8 @@ const struct cmd_entry cmd_confirm_before_entry = { struct cmd_confirm_before_data { struct cmdq_item *item; struct cmd_list *cmdlist; + u_char confirm_key; + int default_yes; }; 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 cmd_find_state *target = cmdq_get_target(item); char *new_prompt; - const char *prompt, *cmd; + const char *confirm_key, *prompt, *cmd; int wait = !args_has(args, 'b'); cdata = xcalloc(1, sizeof *cdata); @@ -79,11 +82,26 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) if (wait) 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) xasprintf(&new_prompt, "%s ", prompt); else { 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, @@ -107,9 +125,9 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s, if (c->flags & CLIENT_DEAD) goto out; - if (s == NULL || *s == '\0') + if (s == NULL) 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; retcode = 0; @@ -123,12 +141,12 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s, } out: - if (item != NULL) { - if (cmdq_get_client(item) != NULL && - cmdq_get_client(item)->session == NULL) - cmdq_get_client(item)->retval = retcode; - cmdq_continue(item); - } + if (item != NULL) { + if (cmdq_get_client(item) != NULL && + cmdq_get_client(item)->session == NULL) + cmdq_get_client(item)->retval = retcode; + cmdq_continue(item); + } return (0); } diff --git a/tmux.1 b/tmux.1 index 30c655eb..4cbb8954 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5807,7 +5807,8 @@ the prompt is shown in the background and the invoking client does not exit until it is dismissed. .Tg confirm .It Xo Ic confirm-before -.Op Fl b +.Op Fl by +.Op Fl c Ar confirm-key .Op Fl p Ar prompt .Op Fl t Ar target-client .Ar command @@ -5828,6 +5829,14 @@ With .Fl b , the prompt is shown in the background and the invoking client does not exit 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 .It Xo Ic display-menu .Op Fl O