Add base game
This commit is contained in:
11
conio/CMakeLists.txt
Normal file
11
conio/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
add_library(
|
||||
conio
|
||||
conio.hpp
|
||||
conio.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
conio
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
30
conio/conio.cpp
Normal file
30
conio/conio.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "conio.hpp"
|
||||
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* Get a character from the console without needing to press enter
|
||||
*/
|
||||
char conio::getch()
|
||||
{
|
||||
char c;
|
||||
struct termios oldattr, newattr;
|
||||
|
||||
// Get the terminal settings
|
||||
tcgetattr(STDIN_FILENO, &oldattr);
|
||||
newattr = oldattr;
|
||||
|
||||
// Disable canonical mode and echo
|
||||
newattr.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
|
||||
|
||||
// Get the character, will not wait for enter because of the new settings
|
||||
std::cin.get(c);
|
||||
|
||||
// Reset the terminal settings back to normal behaviour
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
|
||||
|
||||
return c;
|
||||
}
|
9
conio/conio.hpp
Normal file
9
conio/conio.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef CONIO_HPP
|
||||
#define CONIO_HPP
|
||||
|
||||
namespace conio
|
||||
{
|
||||
char getch();
|
||||
}
|
||||
|
||||
#endif // CONIO_HPP
|
Reference in New Issue
Block a user