#include "bee2/cmd.h"
#ifdef OS_UNIX
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
bool_t cmdTermKbhit()
{
struct termios oldattr, newattr;
int bytesWaiting;
tcgetattr(STDIN_FILENO, &oldattr);
newattr = oldattr;
newattr.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
return bytesWaiting > 0;
}
int cmdTermGetch()
{
struct termios oldattr, newattr;
int ch;
fflush(stdout);
tcgetattr(STDIN_FILENO, &oldattr);
newattr = oldattr;
newattr.c_lflag &= ~(ICANON | ECHO);
newattr.c_cc[VMIN] = 1;
newattr.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
return ch;
}
#elif defined OS_WIN
#include <conio.h>
bool_t cmdTermKbhit()
{
return _kbhit();
}
int cmdTermGetch()
{
return _getch();
}
#else
bool_t cmdTermKbhit()
{
return FALSE;
}
int cmdTermGetch()
{
char ch;
scanf(" %c", &ch);
return ch;
}
#endif