linux input port done
This commit is contained in:
@@ -23,7 +23,8 @@ struct tart_vec2 term_current_size() {
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <threads.h>
|
||||
#include <termios.h>
|
||||
struct tart_vec2 term_current_size() {
|
||||
struct tart_vec2 ret;
|
||||
@@ -60,11 +61,11 @@ void init_termios(int args) {
|
||||
current.c_lflag &= ~ECHO;
|
||||
}
|
||||
|
||||
tcsetattr(0,TCSANOW, ¤t);
|
||||
tcsetattr(0,TCSAFLUSH, ¤t);
|
||||
}
|
||||
|
||||
void reset_termios(void) {
|
||||
tcsetattr(0, TCSANOW, &old);
|
||||
tcsetattr(0, TCSAFLUSH, &old);
|
||||
}
|
||||
|
||||
char term_getch() {
|
||||
@@ -83,4 +84,64 @@ char term_getche() {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
while(1) {
|
||||
set_char_push_back(term_getch());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int term_threaded_input_stop() {
|
||||
pthread_cancel(input_thread);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int term_threaded_input_init() {
|
||||
|
||||
pthread_create(&input_thread, NULL, input_threaded_func, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char term_tinputi(int idx){
|
||||
if(idx < 8) {
|
||||
return __term_input_buffer__[idx];
|
||||
}
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
char* term_tinputb() {
|
||||
return __term_input_buffer__;
|
||||
}
|
||||
|
||||
char term_tinput() {
|
||||
return __term_input_buffer__[0];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void term_disable_cursor() {
|
||||
fputs("\033[?25l", stdout);
|
||||
}
|
||||
|
||||
void term_enable_cursor() {
|
||||
fputs("\033[?25h", stdout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user