feat: input and window

This commit is contained in:
DarthMooMancer
2025-09-04 21:23:05 -04:00
parent 93962961ac
commit 4ce29c2b14
4 changed files with 41 additions and 4 deletions
+4 -3
View File
@@ -6,12 +6,13 @@ include_directories(include)
set(SOURCES
src/main.cpp
src/input.cpp
)
add_executable(connect_four ${SOURCES})
# find_package(Curses REQUIRED)
# include_directories(${CURSES_INCLUDE_DIR})
# target_link_libraries(connect_four ${CURSES_LIBRARIES})
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
target_link_libraries(connect_four ${CURSES_LIBRARIES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+9
View File
@@ -0,0 +1,9 @@
#ifndef INPUT_HPP
#define INPUT_HPP
struct Input {
int _getch = 0;
void get_input(bool &running);
};
#endif
+17
View File
@@ -0,0 +1,17 @@
#include "input.hpp"
#include <ncurses.h>
void Input::get_input(bool &running) {
while(running) {
initscr();
cbreak();
noecho();
_getch = getch();
endwin();
if(_getch == 113) {
running = false;
}
}
}
+11 -1
View File
@@ -1,6 +1,16 @@
#include <iostream>
#include <thread>
#include "input.hpp"
int main() {
std::cout << "Hello World" << std::endl;
Input input;
bool running = true;
std::thread input_thread(&Input::get_input, &input, std::ref(running));
while(running) {
std::cout << "Hello World" << std::endl;
}
input_thread.join();
return 0;
}