mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
pacman: improve select-question
Make use of parseindex like in multiselect, and loop until we get a valid answer like in multiselect. Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
This commit is contained in:
parent
00fec5e250
commit
2dd53e50de
@ -311,7 +311,6 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
|
||||
depstring);
|
||||
free(depstring);
|
||||
select_display(providers);
|
||||
printf("\n");
|
||||
*response = select_question(count);
|
||||
}
|
||||
break;
|
||||
|
@ -815,27 +815,28 @@ int select_question(int count)
|
||||
stream = stderr;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
fprintf(stream, "\n");
|
||||
fprintf(stream, _("Enter a number (default=%d)"), preset);
|
||||
fprintf(stream, ": ");
|
||||
|
||||
if(config->noconfirm) {
|
||||
fprintf(stream, "\n");
|
||||
return(preset-1);
|
||||
break;
|
||||
}
|
||||
|
||||
if(fgets(response, sizeof(response), stdin)) {
|
||||
strtrim(response);
|
||||
if(strlen(response) > 0) {
|
||||
char *endptr = NULL;
|
||||
int n = strtol(response, &endptr, 10);
|
||||
if(*endptr == '\0' && n >= 1 && n <= count) {
|
||||
int n;
|
||||
if(parseindex(response, &n, 1, count) != 0)
|
||||
continue;
|
||||
return(n-1);
|
||||
} else {
|
||||
fprintf(stream, _("Invalid number: %s\n"), response);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(preset-1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user