10
#include <sys/fcntl.h>
18
static struct termios *tty = NULL;
19
static void (*old_sighandler)(int) = NULL;
21
void tty_restore(void) {
23
tcsetattr(STDIN_FILENO, TCSANOW, tty);
26
static void sighandler(int sig) {
28
printf(_("Interrupted\n"));
35
static struct termios t;
38
if(!tcgetattr(STDIN_FILENO, &t)) {
40
old_sig = signal(SIGINT, sighandler);
41
if(old_sig != SIG_ERR)
42
old_sighandler = old_sig;
46
int tty_ask(char *choices, char *fmt, ...) {
50
unsigned char c[READBUF];
55
vfprintf(stdout, fmt, ap);
61
tmp.c_lflag &= ~ICANON;
62
tmp.c_iflag &= ~ICRNL;
66
tcsetattr(STDIN_FILENO, TCSANOW, &tmp);
69
r = read(STDIN_FILENO, c, READBUF);
74
printf(_("Interrupted\n"));
78
if(!r || strchr(" \r", *c))
83
if(choice = strchr(choices, *c)) {
84
printf("%c\n", toupper(*c));
86
return choice - choices;