mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
input: pass through decoded utf8 #121
This commit is contained in:
parent
ad4c8ac58a
commit
6c14a47368
@ -18,6 +18,16 @@ pop_input_keypress(notcurses* nc){
|
|||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assumes there is space, as you presumably just popped it
|
||||||
|
static inline void
|
||||||
|
unpop_keypress(notcurses* nc, int kpress){
|
||||||
|
++nc->inputbuf_occupied;
|
||||||
|
if(nc->inputbuf_valid_starts-- == 0){
|
||||||
|
nc->inputbuf_valid_starts = sizeof(nc->inputbuf) / sizeof(*nc->inputbuf) - 1;
|
||||||
|
}
|
||||||
|
nc->inputbuf[nc->inputbuf_valid_starts] = kpress;
|
||||||
|
}
|
||||||
|
|
||||||
// we assumed escapes can only be composed of 7-bit chars
|
// we assumed escapes can only be composed of 7-bit chars
|
||||||
typedef struct esctrie {
|
typedef struct esctrie {
|
||||||
int special; // composed key terminating here
|
int special; // composed key terminating here
|
||||||
@ -124,10 +134,24 @@ handle_getc(notcurses* nc, int kpress){
|
|||||||
}
|
}
|
||||||
if(kpress < 0x80){
|
if(kpress < 0x80){
|
||||||
return kpress;
|
return kpress;
|
||||||
}else{
|
|
||||||
// FIXME load up zee utf8
|
|
||||||
}
|
}
|
||||||
return 1;
|
char cpoint[MB_CUR_MAX];
|
||||||
|
size_t cpointlen = 0;
|
||||||
|
cpoint[cpointlen] = kpress;
|
||||||
|
// FIXME need to stop as soon as we have a full codepoint urk
|
||||||
|
while(++cpointlen < MB_CUR_MAX - 1 && nc->inputbuf_occupied){
|
||||||
|
int candidate = pop_input_keypress(nc);
|
||||||
|
if(candidate < 0x80){
|
||||||
|
unpop_keypress(nc, candidate);
|
||||||
|
}
|
||||||
|
cpoint[cpointlen] = candidate;
|
||||||
|
}
|
||||||
|
cpoint[cpointlen] = '\0';
|
||||||
|
wchar_t w;
|
||||||
|
if(mbtowc(&w, cpoint, cpointlen) < 0){
|
||||||
|
return (wchar_t)-1;
|
||||||
|
}
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// blocks up through ts (infinite with NULL ts), returning number of events
|
// blocks up through ts (infinite with NULL ts), returning number of events
|
||||||
|
Loading…
Reference in New Issue
Block a user