#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#ifndef WIN32
#include <termios.h>
+#else
+// MinGW defines struct timespec in pthread.h
+#include <pthread.h>
+// for nanosleep()
+#include <framework/mlt_types.h>
+#endif
#include <unistd.h>
#include <sys/time.h>
/** This stores the previous settings
*/
+#ifndef WIN32
static struct termios oldtty;
static int mode = 0;
+#endif
/** This is called automatically on application exit to restore the
previous tty settings.
void term_exit(void)
{
+#ifndef WIN32
if ( mode == 1 )
{
tcsetattr( 0, TCSANOW, &oldtty );
mode = 0;
}
+#endif
}
/** Init terminal so that we can grab keys without blocking.
void term_init( )
{
+#ifndef WIN32
struct termios tty;
tcgetattr( 0, &tty );
mode = 1;
atexit( term_exit );
+#endif
}
/** Check for a keypress without blocking infinitely.
int term_read( )
{
+#ifndef WIN32
int n = 1;
unsigned char ch;
struct timeval tv;
return ch;
return n;
}
+#else
+ struct timespec tm = { 0, 40000000 };
+ nanosleep( &tm, NULL );
+#endif
return -1;
}