2020-11-24 15:41:18 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <brynet/base/Platform.hpp>
|
2021-04-30 16:10:14 +02:00
|
|
|
#include <cstdbool>
|
|
|
|
#include <cstdio>
|
2020-11-24 15:41:18 +01:00
|
|
|
|
|
|
|
#ifdef BRYNET_PLATFORM_WINDOWS
|
|
|
|
#include <conio.h>
|
|
|
|
#else
|
2021-04-30 16:10:14 +02:00
|
|
|
#include <fcntl.h>
|
2020-11-24 15:41:18 +01:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2021-05-14 17:16:45 +02:00
|
|
|
static bool app_kbhit() {
|
2020-11-24 15:41:18 +01:00
|
|
|
#ifdef BRYNET_PLATFORM_WINDOWS
|
2021-05-14 17:16:45 +02:00
|
|
|
return _kbhit();
|
2020-11-24 15:41:18 +01:00
|
|
|
#else
|
2021-05-14 17:16:45 +02:00
|
|
|
struct termios oldt;
|
|
|
|
tcgetattr(STDIN_FILENO, &oldt);
|
|
|
|
auto newt = oldt;
|
|
|
|
newt.c_lflag &= ~(ICANON | ECHO);
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
|
|
|
const auto oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
|
|
|
|
|
|
|
const auto ch = getchar();
|
|
|
|
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
|
|
|
|
|
|
|
if (ch != EOF) {
|
|
|
|
ungetc(ch, stdin);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-04-30 16:10:14 +02:00
|
|
|
#endif
|
|
|
|
}
|