Allow running without TTY (e.g. in Instruments)

Continue running if TTY cannot be opened
This commit is contained in:
Brad Grantham 2016-11-20 12:27:58 -08:00
parent 9554f80a00
commit d212e8f112
1 changed files with 11 additions and 3 deletions

View File

@ -111,21 +111,26 @@ unsigned char get_any_key_down_and_clear_strobe()
return 0x00;
}
bool started = false;
void start_keyboard()
{
// Set raw mode on stdin.
if (ttyraw(0) < 0) {
fprintf(stderr,"Can't go to raw mode.\n");
exit(1);
fprintf(stderr,"Can't go to raw mode. Oh, well!\n");
// exit(1);
return;
}
started = true;
}
void stop_keyboard()
{
if (ttyreset(0) < 0) {
if (started && (ttyreset(0) < 0)) {
fprintf(stderr, "Cannot reset terminal!\n");
exit(-1);
}
started = false;
}
bool peek_key(char *k)
@ -145,6 +150,9 @@ void poll_keyboard()
int i;
char c;
if(!started)
return;
i = read(0, &c, 1);
if (i == -1) {
if (errno == EAGAIN) {