trying to fix input
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
project(TartLib VERSION 0.1)
|
project(TartLib VERSION 0.1)
|
||||||
set( CMAKE_STATIC_LIBRARY_PREFIX "")
|
set( CMAKE_STATIC_LIBRARY_PREFIX "")
|
||||||
set( CMAKE_CXX_STANDARD 11)
|
set( CMAKE_C_STANDARD 11)
|
||||||
set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
set( CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(LIB_SOURCES
|
set(LIB_SOURCES
|
||||||
term.c
|
term.c
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ struct tart_vec2 term_current_size() {
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
struct tart_vec2 term_current_size() {
|
struct tart_vec2 term_current_size() {
|
||||||
struct tart_vec2 ret;
|
struct tart_vec2 ret;
|
||||||
|
|
||||||
@@ -42,4 +44,43 @@ struct tart_vec2 term_current_size() {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct termios old, current;
|
||||||
|
|
||||||
|
void init_termios(int args) {
|
||||||
|
tcgetattr(0, &old);
|
||||||
|
|
||||||
|
current = old;
|
||||||
|
|
||||||
|
current.c_lflag &= ~ICANON;
|
||||||
|
|
||||||
|
if(args == 0x01) {
|
||||||
|
current.c_lflag |= ECHO;
|
||||||
|
} else {
|
||||||
|
current.c_lflag &= ~ECHO;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcsetattr(0,TCSANOW, ¤t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_termios(void) {
|
||||||
|
tcsetattr(0, TCSANOW, &old);
|
||||||
|
}
|
||||||
|
|
||||||
|
char term_getch() {
|
||||||
|
char tmp;
|
||||||
|
init_termios(0x00);
|
||||||
|
tmp = getchar();
|
||||||
|
reset_termios();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
char term_getche() {
|
||||||
|
char tmp;
|
||||||
|
init_termios(0x01);
|
||||||
|
tmp = getchar();
|
||||||
|
reset_termios();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,4 +13,7 @@
|
|||||||
|
|
||||||
struct tart_vec2 term_current_size();
|
struct tart_vec2 term_current_size();
|
||||||
|
|
||||||
|
char term_getch();
|
||||||
|
char term_getche();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,3 +11,9 @@ add_executable(${PROJECT_NAME} ${SOURCES} )
|
|||||||
target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||||
|
|
||||||
add_test(${PROJECT_NAME} "${CMAKE_SOURCE_DIR}/bin/testing.exe")
|
add_test(${PROJECT_NAME} "${CMAKE_SOURCE_DIR}/bin/testing.exe")
|
||||||
|
|
||||||
|
project(InputTartTest)
|
||||||
|
set( CMAKE_CXX_STANDARD 11)
|
||||||
|
set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
add_executable(${PROJECT_NAME} input.cpp )
|
||||||
|
target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||||
|
|||||||
30
testing/input.cpp
Normal file
30
testing/input.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <tart.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <threads.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
int counter = 0;
|
||||||
|
int main (int argc, char *argv[]) {
|
||||||
|
char t = ' ';
|
||||||
|
while(t != 'q') {
|
||||||
|
std::cout << "input a char" << ftell(stdin) <<" [";
|
||||||
|
fseek(stdin, 0, SEEK_END);
|
||||||
|
if(ftell(stdin) > 0) {
|
||||||
|
t = term_getche();
|
||||||
|
rewind(stdin);
|
||||||
|
std::cout << t;
|
||||||
|
std::cout << "]\n\r ";
|
||||||
|
return 0;
|
||||||
|
}else {
|
||||||
|
std::cout << "eof";
|
||||||
|
std::cout << "]\r ";
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec b;
|
||||||
|
b.tv_sec = 1;
|
||||||
|
thrd_sleep(&b, NULL); // sleep 1 sec
|
||||||
|
}
|
||||||
|
std::cout << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user