core: rework the confirmation spawn prompt

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.
This commit is contained in:
Franck Bui 2016-11-07 17:14:59 +01:00
parent 2bcd3c26fe
commit d172b175f6
2 changed files with 29 additions and 19 deletions

1
NEWS
View File

@ -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

View File

@ -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;
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;
case 's':
printf("Skipping execution.\n");
r = CONFIRM_PRETEND_SUCCESS;
break;
case 'y':
r = CONFIRM_EXECUTE;
break;
default:
assert_not_reached("Unhandled choice");
}
restore_stdio: