added windows input port and added defines for windows and linux systems
This commit is contained in:
@@ -7,6 +7,7 @@ set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set( CMAKE_C_STANDARD 11)
|
||||
set( CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/libs)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
|
||||
@@ -3,6 +3,7 @@ set( CMAKE_STATIC_LIBRARY_PREFIX "")
|
||||
set( CMAKE_C_STANDARD 11)
|
||||
set( CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
set(LIB_SOURCES
|
||||
term.c
|
||||
term.h
|
||||
@@ -10,4 +11,13 @@ set(LIB_SOURCES
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${LIB_SOURCES})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC "../includes/")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "_LINUX")
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "_WIN32")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "_WIN64")
|
||||
endif()
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
#include "term.h"
|
||||
#include <stdio.h>
|
||||
|
||||
char __term_input_buffer__[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
||||
void set_char_push_back(char t) {
|
||||
char tmp1;
|
||||
char hold1;
|
||||
char hold2;
|
||||
hold1 = __term_input_buffer__[0];
|
||||
for(int i = 0; i < 8 - 1; i++) {
|
||||
hold2 = __term_input_buffer__[i+1];
|
||||
__term_input_buffer__[i+1] = hold1;
|
||||
hold1 = hold2;
|
||||
|
||||
}
|
||||
__term_input_buffer__[0] = t;
|
||||
}
|
||||
|
||||
// if windows is defined.
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
#include <Windows.h>
|
||||
#include <conio.h>
|
||||
|
||||
|
||||
|
||||
|
||||
struct tart_vec2 term_current_size() {
|
||||
struct tart_vec2 ret;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
@@ -19,6 +40,30 @@ struct tart_vec2 term_current_size() {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
HANDLE __term_input_thread;
|
||||
int __term_input_thread_stop;
|
||||
|
||||
DWORD WINAPI input_threaded_func(void* data) {
|
||||
while(__term_input_thread_stop == 1) {
|
||||
if(_kbhit())
|
||||
set_char_push_back(_getch());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int term_threaded_input_init() {
|
||||
__term_input_thread_stop = 1;
|
||||
__term_input_thread = CreateThread(NULL,0,input_threaded_func,NULL, 0, NULL);
|
||||
return 0;
|
||||
}
|
||||
int term_threaded_input_stop() {
|
||||
__term_input_thread_stop = 0;
|
||||
WaitForSingleObject(__term_input_thread, INFINITE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
@@ -85,22 +130,8 @@ char term_getche() {
|
||||
}
|
||||
|
||||
|
||||
char __term_input_buffer__[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
||||
pthread_t input_thread;
|
||||
|
||||
void set_char_push_back(char t) {
|
||||
char tmp1;
|
||||
char hold1;
|
||||
char hold2;
|
||||
hold1 = __term_input_buffer__[0];
|
||||
for(int i = 0; i < 8 - 1; i++) {
|
||||
hold2 = __term_input_buffer__[i+1];
|
||||
__term_input_buffer__[i+1] = hold1;
|
||||
hold1 = hold2;
|
||||
|
||||
}
|
||||
__term_input_buffer__[0] = t;
|
||||
}
|
||||
|
||||
void* input_threaded_func(void* vargp) {
|
||||
int myid = getpid();
|
||||
@@ -121,6 +152,9 @@ int term_threaded_input_init() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
char term_tinputi(int idx){
|
||||
if(idx < 8) {
|
||||
return __term_input_buffer__[idx];
|
||||
@@ -135,9 +169,6 @@ char* term_tinputb() {
|
||||
char term_tinput() {
|
||||
return __term_input_buffer__[0];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void term_disable_cursor() {
|
||||
fputs("\033[?25l", stdout);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#include <tart.h>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <threads.h>
|
||||
#include <termios.h>
|
||||
#ifdef _LINUX
|
||||
#endif
|
||||
|
||||
char* bbuf;
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
int n;
|
||||
int counter = 0;
|
||||
struct termios te;
|
||||
term_disable_cursor();
|
||||
term_threaded_input_init();
|
||||
bbuf = term_tinputb();
|
||||
|
||||
Reference in New Issue
Block a user