mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 09:39:03 -04:00
Add all handled signals to ppoll() set
This addresses an issue where callers of notcurses_getc_blocking() wouldn't exit on SIGINT etc. until another keystroke was received. The exit is now immediate, and the proper exit code is propagated.
This commit is contained in:
parent
6f2c45a0ef
commit
04e067c202
@ -3,13 +3,17 @@
|
|||||||
|
|
||||||
sig_atomic_t resize_seen = 0;
|
sig_atomic_t resize_seen = 0;
|
||||||
|
|
||||||
|
// 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),
|
||||||
|
// return it, and pop it from the queue.
|
||||||
static int
|
static int
|
||||||
handle_getc(const notcurses* nc __attribute__ ((unused)), cell* c, int kpress,
|
handle_getc(const notcurses* nc __attribute__ ((unused)), cell* c, int kpress,
|
||||||
ncspecial_key* special){
|
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;
|
||||||
}
|
}
|
||||||
|
// FIXME add it to the queue, then consult queue
|
||||||
*special = 0;
|
*special = 0;
|
||||||
if(kpress == 0x04){ // ctrl-d
|
if(kpress == 0x04){ // ctrl-d
|
||||||
return -1;
|
return -1;
|
||||||
@ -30,6 +34,7 @@ int notcurses_getc(const notcurses* nc, cell* c, ncspecial_key* special){
|
|||||||
*special = NCKEY_RESIZE;
|
*special = NCKEY_RESIZE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
// FIXME check queue
|
||||||
int r = getc(nc->ttyinfp);
|
int r = getc(nc->ttyinfp);
|
||||||
if(r < 0){
|
if(r < 0){
|
||||||
return r;
|
return r;
|
||||||
@ -49,15 +54,18 @@ int notcurses_getc_blocking(const notcurses* nc, cell* c, ncspecial_key* special
|
|||||||
sigset_t smask;
|
sigset_t smask;
|
||||||
sigfillset(&smask);
|
sigfillset(&smask);
|
||||||
sigdelset(&smask, SIGWINCH);
|
sigdelset(&smask, SIGWINCH);
|
||||||
|
sigdelset(&smask, SIGINT);
|
||||||
|
sigdelset(&smask, SIGQUIT);
|
||||||
|
sigdelset(&smask, SIGSEGV);
|
||||||
while((pret = ppoll(&pfd, 1, NULL, &smask)) >= 0){
|
while((pret = ppoll(&pfd, 1, NULL, &smask)) >= 0){
|
||||||
if(pret == 0){
|
if(pret == 0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
r = getc(nc->ttyinfp);
|
r = notcurses_getc(nc, c, special);
|
||||||
if(r < 0){
|
if(r < 0){
|
||||||
break; // want EINTR handling below
|
break; // want EINTR handling below
|
||||||
}
|
}
|
||||||
return handle_getc(nc, c, r, special);
|
return r;
|
||||||
}
|
}
|
||||||
if(errno == EINTR){
|
if(errno == EINTR){
|
||||||
if(resize_seen){
|
if(resize_seen){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user