input: handle modifiers+mouse (alt, shift, ctrl) #226

This commit is contained in:
nick black 2019-12-27 01:23:25 -05:00 committed by Nick Black
parent b9a10cad9f
commit bd034c983a
3 changed files with 16 additions and 5 deletions

View File

@ -252,7 +252,9 @@ typedef struct ncinput {
char32_t id; // identifier. Unicode codepoint or synthesized NCKEY event
int y; // y cell coordinate of event, -1 for undefined
int x; // x cell coordinate of event, -1 for undefined
// FIXME modifiers (alt, etc?)
bool alt; // was alt held?
bool shift; // was shift held?
bool ctrl; // was ctrl held?
} ncinput;
// See ppoll(2) for more detail. Provide a NULL 'ts' to block at length, a 'ts'

View File

@ -176,16 +176,19 @@ int main(void){
if(ncplane_cursor_move_yx(n, y, 0)){
break;
}
ncplane_set_fg_rgb(n, 0xd0, 0xd0, 0xd0);
ncplane_printf(n, "%c%c%c ", ni.alt ? 'A' : 'a', ni.ctrl ? 'C' : 'c',
ni.shift ? 'S' : 's');
if(r < 0x80){
ncplane_set_fg_rgb(n, 128, 250, 64);
if(ncplane_printf(n, "Got ASCII: [0x%02x (%03d)] '%lc'",
if(ncplane_printf(n, "ASCII: [0x%02x (%03d)] '%lc'",
r, r, iswprint(r) ? r : printutf8(r)) < 0){
break;
}
}else{
if(wchar_supppuab_p(r)){
ncplane_set_fg_rgb(n, 250, 64, 128);
if(ncplane_printf(n, "Got special key: [0x%02x (%02d)] '%s'",
if(ncplane_printf(n, "Special: [0x%02x (%02d)] '%s'",
r, r, nckeystr(r)) < 0){
break;
}
@ -197,7 +200,7 @@ int main(void){
}
}else{
ncplane_set_fg_rgb(n, 64, 128, 250);
ncplane_printf(n, "Got UTF-8: [0x%08x] '%lc'", r, r);
ncplane_printf(n, "Unicode: [0x%08x] '%lc'", r, r);
}
}
if(dim_rows(n)){

View File

@ -141,6 +141,9 @@ handle_csi(notcurses* nc, ncinput* ni){
}else{
break;
}
ni->ctrl = param & 0x10;
ni->alt = param & 0x08;
ni->shift = param & 0x04;
param = 0;
}else if(isdigit(candidate)){
param *= 10;
@ -194,7 +197,7 @@ handle_csi(notcurses* nc, ncinput* ni){
// return it, and pop it from the queue.
static char32_t
handle_getc(notcurses* nc, int kpress, ncinput* ni){
// fprintf(stderr, "KEYPRESS: %d\n", kpress);
//fprintf(stderr, "KEYPRESS: %d\n", kpress);
if(kpress < 0){
return -1;
}
@ -300,6 +303,9 @@ handle_input(notcurses* nc, ncinput* ni){
static char32_t
handle_ncinput(notcurses* nc, ncinput* ni){
if(ni){
memset(ni, 0, sizeof(*ni));
}
char32_t r = handle_input(nc, ni);
if(ni){
ni->id = r;