|
|
@ -8,7 +8,7 @@ sig_atomic_t resize_seen = 0;
|
|
|
|
static inline int
|
|
|
|
static inline int
|
|
|
|
pop_input_keypress(notcurses* nc){
|
|
|
|
pop_input_keypress(notcurses* nc){
|
|
|
|
int candidate = nc->inputbuf[nc->inputbuf_valid_starts];
|
|
|
|
int candidate = nc->inputbuf[nc->inputbuf_valid_starts];
|
|
|
|
fprintf(stderr, "DEOCCUPY: %u@%u read: %d\n", nc->inputbuf_occupied, nc->inputbuf_valid_starts, nc->inputbuf[nc->inputbuf_valid_starts]);
|
|
|
|
// fprintf(stderr, "DEOCCUPY: %u@%u read: %d\n", nc->inputbuf_occupied, nc->inputbuf_valid_starts, nc->inputbuf[nc->inputbuf_valid_starts]);
|
|
|
|
if(++nc->inputbuf_valid_starts == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf)){
|
|
|
|
if(++nc->inputbuf_valid_starts == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf)){
|
|
|
|
nc->inputbuf_valid_starts = 0;
|
|
|
|
nc->inputbuf_valid_starts = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -16,17 +16,83 @@ fprintf(stderr, "DEOCCUPY: %u@%u read: %d\n", nc->inputbuf_occupied, nc->inputbu
|
|
|
|
return candidate;
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we assumed escapes can only be composed of 7-bit chars
|
|
|
|
|
|
|
|
typedef struct esctrie {
|
|
|
|
|
|
|
|
ncspecial_key special; // escape terminating here
|
|
|
|
|
|
|
|
struct esctrie** trie; // if non-NULL, next level of radix-128 trie
|
|
|
|
|
|
|
|
} esctrie;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static esctrie*
|
|
|
|
|
|
|
|
create_esctrie_node(ncspecial_key special){
|
|
|
|
|
|
|
|
esctrie* e = malloc(sizeof(*e));
|
|
|
|
|
|
|
|
if(e){
|
|
|
|
|
|
|
|
e->special = special;
|
|
|
|
|
|
|
|
e->trie = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void input_free_esctrie(esctrie** eptr){
|
|
|
|
|
|
|
|
esctrie* e;
|
|
|
|
|
|
|
|
if( (e = *eptr) ){
|
|
|
|
|
|
|
|
if(e->trie){
|
|
|
|
|
|
|
|
int z;
|
|
|
|
|
|
|
|
for(z = 0 ; z < 0x80 ; ++z){
|
|
|
|
|
|
|
|
if(e->trie[z]){
|
|
|
|
|
|
|
|
input_free_esctrie(&e->trie[z]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(e->trie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int input_add_escape(notcurses* nc, const char* esc, ncspecial_key special){
|
|
|
|
|
|
|
|
esctrie** cur;
|
|
|
|
|
|
|
|
fprintf(stderr, "ADDING: %s for %d\n", esc, special);
|
|
|
|
|
|
|
|
if(esc[0] != ESC || strlen(esc) < 2){ // assume ESC prefix + content
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
|
|
|
++esc;
|
|
|
|
|
|
|
|
int validate = *esc;
|
|
|
|
|
|
|
|
if(validate < 0 || validate >= 0x80){
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nc->inputescapes == NULL){
|
|
|
|
|
|
|
|
cur = &nc->inputescapes;
|
|
|
|
|
|
|
|
}else if(validate){
|
|
|
|
|
|
|
|
if((*cur)->trie == NULL){
|
|
|
|
|
|
|
|
const size_t tsize = sizeof((*cur)->trie) * 0x80;
|
|
|
|
|
|
|
|
(*cur)->trie = malloc(tsize);
|
|
|
|
|
|
|
|
memset((*cur)->trie, 0, tsize);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = &(*cur)->trie[validate];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*cur == NULL){
|
|
|
|
|
|
|
|
if((*cur = create_esctrie_node(NCKEY_INVALID)) == NULL){
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}while(*esc);
|
|
|
|
|
|
|
|
if((*cur)->special){ // already had one here!
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(*cur)->special = special;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add the keypress we just read to our input queue (assuming there is room).
|
|
|
|
// add the keypress we just read to our input queue (assuming there is room).
|
|
|
|
// if there is a full UTF8 codepoint or keystroke (composed or otherwise),
|
|
|
|
// if there is a full UTF8 codepoint or keystroke (composed or otherwise),
|
|
|
|
// return it, and pop it from the queue.
|
|
|
|
// return it, and pop it from the queue.
|
|
|
|
static int
|
|
|
|
static int
|
|
|
|
handle_getc(notcurses* nc, cell* c, int kpress, ncspecial_key* special){
|
|
|
|
handle_getc(notcurses* nc, cell* c, int kpress, ncspecial_key* special){
|
|
|
|
fprintf(stderr, "KEYPRESS: %d\n", kpress);
|
|
|
|
// fprintf(stderr, "KEYPRESS: %d\n", kpress);
|
|
|
|
if(kpress < 0){
|
|
|
|
if(kpress < 0){
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(kpress == ESC){
|
|
|
|
if(kpress == ESC){
|
|
|
|
fprintf(stderr, "ESCAPE OH SHIT\n");
|
|
|
|
|
|
|
|
// FIXME delay a little waiting for more?
|
|
|
|
// FIXME delay a little waiting for more?
|
|
|
|
while(nc->inputbuf_occupied){
|
|
|
|
while(nc->inputbuf_occupied){
|
|
|
|
int candidate = pop_input_keypress(nc);
|
|
|
|
int candidate = pop_input_keypress(nc);
|
|
|
|