aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 36f78ceb..f452bf3c 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -958,24 +958,17 @@ void terminal_size(unsigned *x, unsigned *y)
}
}
-// This should use a raw tty, fixit later.
int yesno(char *prompt, int def)
{
- FILE *fps[] = {stdin, stdout, stderr};
- int i;
char buf;
- for (i=0; i<3; i++) if (isatty(i)) break;
- if (i == 3) return 1;
-
- fprintf(fps[i], "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
- fflush(fps[i]);
- while (fread(&buf, 1, 1, fps[i])) {
- if (tolower(buf) == 'y') def = 1;
- if (tolower(buf) == 'n') def = 0;
- else if (!isspace(buf)) continue;
+ fprintf(stderr, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' : 'N');
+ fflush(stderr);
+ while (fread(&buf, 1, 1, stdin)) {
+ int new;
- break;
+ if (isspace(buf)) break;
+ if (-1 != (new = stridx("ny", tolower(buf)))) def = new;
}
return def;