From d172b175f6d43d68929975e3baa3837da677bc68 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 7 Nov 2016 17:14:59 +0100 Subject: core: rework the confirmation spawn prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously it was "[Yes, Fail, Skip]" which is pretty misleading because it suggests that the whole word needs to be entered instead of a single char. Also this won't fit well when we'll extend the number of choices. This patch addresses this by changing the choice hint with "[y, f, s – h for help]" so it's now clear that a single letter has to be entered. It also introduces a new choice 'h' which describes all possible choices since a single letter can be not descriptive enough for new users. It also allow to stick with the same hint string regardless of how many choices we will support. --- NEWS | 1 + src/core/execute.c | 47 ++++++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index fbd9afa2cb..fde3d6caf6 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ CHANGES WITH 233 in spe following choices: (f)ail, don't execute the command and pretend it failed + (h)elp (s)kip, don't execute the command and pretend it succeeded (y)es, execute the command diff --git a/src/core/execute.c b/src/core/execute.c index 0273b1966f..65ba9acf7a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -739,27 +739,36 @@ static int ask_for_confirmation(const char *vc, const char *cmdline) { goto restore_stdio; } - r = ask_char(&c, "yfs", "Execute %s? [Yes, Fail, Skip] ", e); - if (r < 0) { - write_confirm_error_fd(r, STDOUT_FILENO); - r = CONFIRM_EXECUTE; - goto restore_stdio; - } + for (;;) { + r = ask_char(&c, "yfsh", "Execute %s? [y, f, s – h for help] ", e); + if (r < 0) { + write_confirm_error_fd(r, STDOUT_FILENO); + r = CONFIRM_EXECUTE; + goto restore_stdio; + } - switch (c) { - case 'f': - printf("Failing execution.\n"); - r = CONFIRM_PRETEND_FAILURE; - break; - case 's': - printf("Skipping execution.\n"); - r = CONFIRM_PRETEND_SUCCESS; - break; - case 'y': - r = CONFIRM_EXECUTE; + switch (c) { + case 'f': + printf("Failing execution.\n"); + r = CONFIRM_PRETEND_FAILURE; + break; + case 'h': + printf(" f - fail, don't execute the command and pretend it failed\n" + " h - help\n" + " s - skip, don't execute the command and pretend it succeeded\n" + " y - yes, execute the command\n"); + continue; + case 's': + printf("Skipping execution.\n"); + r = CONFIRM_PRETEND_SUCCESS; + break; + case 'y': + r = CONFIRM_EXECUTE; + break; + default: + assert_not_reached("Unhandled choice"); + } break; - default: - assert_not_reached("Unhandled choice"); } restore_stdio: -- cgit v1.2.3-54-g00ecf