mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
notcurses_stop: restore nonblocking state #1090
This commit is contained in:
parent
f09ed74e84
commit
1e77fcc5c5
20
src/lib/fd.c
20
src/lib/fd.c
@ -79,15 +79,25 @@ ncfdplane_thread(void* vncfp){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_fd_nonblocking(int fd){
|
int set_fd_nonblocking(int fd, unsigned state, unsigned* oldstate){
|
||||||
int flags = fcntl(fd, F_GETFL, 0);
|
int flags = fcntl(fd, F_GETFL, 0);
|
||||||
if(flags < 0){
|
if(flags < 0){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(flags & O_NONBLOCK){
|
if(oldstate){
|
||||||
return 0;
|
*oldstate = flags & O_NONBLOCK;
|
||||||
|
}
|
||||||
|
if(state){
|
||||||
|
if(flags & O_NONBLOCK){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
flags |= O_NONBLOCK;
|
||||||
|
}else{
|
||||||
|
if(!(flags & O_NONBLOCK)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
flags &= ~O_NONBLOCK;
|
||||||
}
|
}
|
||||||
flags |= O_NONBLOCK;
|
|
||||||
if(fcntl(fd, F_SETFL, flags)){
|
if(fcntl(fd, F_SETFL, flags)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -188,7 +198,7 @@ launch_pipe_process(int* pipe, int* pidfd){
|
|||||||
}
|
}
|
||||||
}else if(p > 0){ // parent
|
}else if(p > 0){ // parent
|
||||||
*pipe = pipes[0];
|
*pipe = pipes[0];
|
||||||
set_fd_nonblocking(*pipe);
|
set_fd_nonblocking(*pipe, 1, NULL);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -373,6 +373,7 @@ typedef struct notcurses {
|
|||||||
int loglevel;
|
int loglevel;
|
||||||
palette256 palette; // 256-indexed palette can be used instead of/with RGB
|
palette256 palette; // 256-indexed palette can be used instead of/with RGB
|
||||||
bool palette_damage[NCPALETTESIZE];
|
bool palette_damage[NCPALETTESIZE];
|
||||||
|
unsigned stdio_blocking_save; // was stdio blocking at entry? restore on stop.
|
||||||
} notcurses;
|
} notcurses;
|
||||||
|
|
||||||
#include "blitset.h"
|
#include "blitset.h"
|
||||||
@ -1152,7 +1153,7 @@ int ncinputlayer_init(ncinputlayer* nilayer, FILE* infp);
|
|||||||
// FIXME absorb into ncinputlayer_init()
|
// FIXME absorb into ncinputlayer_init()
|
||||||
int cbreak_mode(int ttyfd, const struct termios* tpreserved);
|
int cbreak_mode(int ttyfd, const struct termios* tpreserved);
|
||||||
|
|
||||||
int set_fd_nonblocking(int fd);
|
int set_fd_nonblocking(int fd, unsigned state, unsigned* oldstate);
|
||||||
|
|
||||||
// Given the four channels arguments, verify that:
|
// Given the four channels arguments, verify that:
|
||||||
//
|
//
|
||||||
|
@ -777,6 +777,7 @@ void notcurses_stats_reset(notcurses* nc, ncstats* stats){
|
|||||||
// the environment / terminal definition.
|
// the environment / terminal definition.
|
||||||
static void
|
static void
|
||||||
init_banner_warnings(const notcurses* nc, FILE* out){
|
init_banner_warnings(const notcurses* nc, FILE* out){
|
||||||
|
// might be using stderr, so don't just reuse stdout decision
|
||||||
const bool tty = isatty(fileno(out));
|
const bool tty = isatty(fileno(out));
|
||||||
if(tty){
|
if(tty){
|
||||||
term_fg_palindex(nc, out, nc->tcache.colors <= 88 ? 1 % nc->tcache.colors : 0xcb);
|
term_fg_palindex(nc, out, nc->tcache.colors <= 88 ? 1 % nc->tcache.colors : 0xcb);
|
||||||
@ -1064,7 +1065,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
|
|||||||
if(ncinputlayer_init(&ret->input, stdin)){
|
if(ncinputlayer_init(&ret->input, stdin)){
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if(set_fd_nonblocking(ret->input.ttyinfd)){
|
if(set_fd_nonblocking(ret->input.ttyinfd, 1, &ret->stdio_blocking_save)){
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
// Neither of these is supported on e.g. the "linux" virtual console.
|
// Neither of these is supported on e.g. the "linux" virtual console.
|
||||||
@ -1168,6 +1169,7 @@ int notcurses_stop(notcurses* nc){
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
if(nc){
|
if(nc){
|
||||||
ret |= notcurses_stop_minimal(nc);
|
ret |= notcurses_stop_minimal(nc);
|
||||||
|
ret |= set_fd_nonblocking(nc->input.ttyinfd, nc->stdio_blocking_save, NULL);
|
||||||
if(nc->stdplane){
|
if(nc->stdplane){
|
||||||
notcurses_drop_planes(nc);
|
notcurses_drop_planes(nc);
|
||||||
free_plane(nc->stdplane);
|
free_plane(nc->stdplane);
|
||||||
|
Loading…
Reference in New Issue
Block a user