mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
48 lines
884 B
C++
48 lines
884 B
C++
#pragma once
|
|
|
|
#include <signal.h>
|
|
|
|
#include <brynet/base/Platform.hpp>
|
|
#include <cstdbool>
|
|
#include <cstdio>
|
|
|
|
#ifdef BRYNET_PLATFORM_WINDOWS
|
|
#include <conio.h>
|
|
#else
|
|
#include <fcntl.h>
|
|
#include <termios.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
namespace brynet { namespace base {
|
|
|
|
static bool app_kbhit()
|
|
{
|
|
#ifdef BRYNET_PLATFORM_WINDOWS
|
|
return _kbhit();
|
|
#else
|
|
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;
|
|
#endif
|
|
}
|
|
|
|
}}// namespace brynet::base
|