update: better way to handle yes no prompt
This commit is contained in:
32
src/log.c
32
src/log.c
@ -95,7 +95,7 @@ void details(const char *msg, ...) {
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
|
||||
printf(" "COLOR_RESET);
|
||||
printf(" " COLOR_RESET);
|
||||
vprintf(msg, args);
|
||||
printf(COLOR_RESET "\n");
|
||||
|
||||
@ -139,18 +139,32 @@ void input(const char *msg, ...) {
|
||||
}
|
||||
|
||||
bool yesno(const char *msg){
|
||||
char question[strlen(msg)+12], inp[2] = {'n','\0'}, c;
|
||||
sprintf(question, "%s [y/n]? ", msg);
|
||||
if(env_mc_yes())
|
||||
return true;
|
||||
|
||||
char *yes[] = {_("y"), _("Y")};
|
||||
char *no[] = {_("n"), _("N")};
|
||||
|
||||
char question[strlen(msg)+12], c;
|
||||
sprintf(question, _("%s [y/N] "), msg);
|
||||
|
||||
while(true){
|
||||
input(question);
|
||||
scanf("%c", &c);
|
||||
inp[0] = c;
|
||||
|
||||
if(eq(inp, _("y")) || eq(inp, _("Y")))
|
||||
return true;
|
||||
else if(eq(inp, _("n")) || eq(inp, _("N")))
|
||||
|
||||
int c = getchar();
|
||||
if(c == '\n')
|
||||
return false;
|
||||
getchar();
|
||||
|
||||
for(int i = 0; i < sizeof(yes)/sizeof(char*); i++){
|
||||
if(yes[i][0] == c)
|
||||
return true;
|
||||
}
|
||||
|
||||
for(int i = 0; i < sizeof(no)/sizeof(char*); i++){
|
||||
if(no[i][0] == c)
|
||||
return false;
|
||||
}
|
||||
|
||||
error(_("Please answer with y/n"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user