mirror of
https://github.com/remko/waforth
synced 2024-12-27 09:59:29 +01:00
standalone: Implement KEY
This commit is contained in:
parent
7a1e7de085
commit
e8202a153d
1 changed files with 11 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "waforth_core.h"
|
||||
#include "wasm.h"
|
||||
|
@ -58,7 +59,16 @@ wasm_trap_t *read_cb(const wasm_val_vec_t *args, wasm_val_vec_t *results) {
|
|||
}
|
||||
|
||||
wasm_trap_t *key_cb(const wasm_val_vec_t *args, wasm_val_vec_t *results) {
|
||||
// TODO
|
||||
struct termios old, current;
|
||||
tcgetattr(0, &old);
|
||||
current = old;
|
||||
current.c_lflag &= ~ICANON;
|
||||
current.c_lflag &= ~ECHO;
|
||||
tcsetattr(0, TCSANOW, ¤t);
|
||||
char ch = getchar();
|
||||
tcsetattr(0, TCSANOW, &old);
|
||||
results->data[0].kind = WASM_I32;
|
||||
results->data[0].of.i32 = ch;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue