diff --git a/src/lib/input.c b/src/lib/input.c index 65c99dcd4..8de79c1c8 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -388,13 +388,13 @@ static char32_t handle_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin, const sigset_t* sigmask){ // we once used getc() here (and kept ttyinfp, a FILE*, instead of the file - // descriptor ttyinfd), but under tmux, the first time running getc() would + // descriptor infd), but under tmux, the first time running getc() would // (bewilderingly) see a series of terminal reset codes emitted. this has // never been explained to my satisfaction, but we can work around it by // using a lower-level read() anyway. // see https://github.com/dankamongmen/notcurses/issues/1314 for more info. unsigned char c; - while(!input_queue_full(nc) && read(nc->ttyinfd, &c, 1) > 0){ + while(!input_queue_full(nc) && read(nc->infd, &c, 1) > 0){ nc->inputbuf[nc->inputbuf_write_at] = c; //fprintf(stderr, "OCCUPY: %u@%u read: %d\n", nc->inputbuf_occupied, nc->inputbuf_write_at, nc->inputbuf[nc->inputbuf_write_at]); if(++nc->inputbuf_write_at == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf)){ @@ -402,7 +402,7 @@ handle_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin, } ++nc->inputbuf_occupied; const struct timespec ts = {}; - if(block_on_input(nc->ttyinfd, &ts, sigmask) < 1){ + if(block_on_input(nc->infd, &ts, sigmask) < 1){ break; } } @@ -456,7 +456,7 @@ ncinputlayer_prestamp(ncinputlayer* nc, const struct timespec *ts, return handle_queued_input(nc, ni, leftmargin, topmargin); } errno = 0; - if(block_on_input(nc->ttyinfd, ts, sigmask) > 0){ + if(block_on_input(nc->infd, ts, sigmask) > 0){ //fprintf(stderr, "%d events from input!\n", events); return handle_ncinput(nc, ni, leftmargin, topmargin, sigmask); } diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 21b40ac18..c8a59cfe7 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -946,7 +946,7 @@ void init_lang(struct notcurses* nc){ int ncinputlayer_init(ncinputlayer* nilayer, FILE* infp){ setbuffer(infp, NULL, 0); nilayer->inputescapes = NULL; - nilayer->ttyinfd = fileno(infp); + nilayer->infd = fileno(infp); if(prep_special_keys(nilayer)){ return -1; } @@ -991,8 +991,7 @@ int notcurses_check_pixel_support(notcurses* nc){ // FIXME cut this up into a few distinct pieces, yearrrgh notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ - notcurses_options defaultopts; - memset(&defaultopts, 0, sizeof(defaultopts)); + notcurses_options defaultopts = { }; if(!opts){ opts = &defaultopts; } @@ -1089,7 +1088,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ goto err; } ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS; - if(set_fd_nonblocking(ret->tcache.input.ttyinfd, 1, &ret->stdio_blocking_save)){ + if(set_fd_nonblocking(ret->tcache.input.infd, 1, &ret->stdio_blocking_save)){ goto err; } if(ncvisual_init(ret->loglevel)){ @@ -1203,7 +1202,7 @@ int notcurses_stop(notcurses* nc){ int ret = 0; if(nc){ ret |= notcurses_stop_minimal(nc); - ret |= set_fd_nonblocking(nc->tcache.input.ttyinfd, nc->stdio_blocking_save, NULL); + ret |= set_fd_nonblocking(nc->tcache.input.infd, nc->stdio_blocking_save, NULL); if(nc->stdplane){ notcurses_drop_planes(nc); free_plane(nc->stdplane); @@ -2612,11 +2611,11 @@ int notcurses_lex_margins(const char* op, notcurses_options* opts){ } int notcurses_inputready_fd(notcurses* n){ - return n->tcache.input.ttyinfd; + return n->tcache.input.infd; } int ncdirect_inputready_fd(ncdirect* n){ - return n->tcache.input.ttyinfd; + return n->tcache.input.infd; } // FIXME speed this up, PoC diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index eb3278bcc..8dd795b5f 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -255,20 +255,17 @@ send_initial_queries(int fd){ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, unsigned noaltscreen, unsigned nocbreak){ memset(ti, 0, sizeof(*ti)); - ti->utf8 = utf8; if(fd >= 0){ - if(tcgetattr(fd, &ti->tpreserved)){ - fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", fd, strerror(errno)); - return -1; - } if(send_initial_queries(fd)){ fprintf(stderr, "Error issuing terminal queries on %d\n", fd); return -1; } + if(tcgetattr(fd, &ti->tpreserved)){ + fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", fd, strerror(errno)); + return -1; + } } - if(ncinputlayer_init(&ti->input, stdin)){ - return -1; - } + ti->utf8 = utf8; if(!nocbreak){ if(cbreak_mode(fd, &ti->tpreserved)){ return -1; @@ -423,6 +420,9 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, goto err; } } + if(ncinputlayer_init(&ti->input, stdin)){ + return -1; + } if(apply_term_heuristics(ti, termname, fd)){ goto err; } diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 5110b2df2..6cac5d609 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -60,7 +60,7 @@ typedef enum { } escape_e; typedef struct ncinputlayer { - int ttyinfd; // file descriptor for processing input + int infd; // file descriptor for processing input, from stdin unsigned char inputbuf[BUFSIZ]; // we keep a wee ringbuffer of input queued up for delivery. if // inputbuf_occupied == sizeof(inputbuf), there is no room. otherwise, data