diff --git a/src/lib/direct.c b/src/lib/direct.c index c2d308627..96e8ca163 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -973,7 +973,11 @@ int ncdirect_stop(ncdirect* nc){ char* ncdirect_readline(ncdirect* n, const char* prompt){ const char* u7 = get_escape(&n->tcache, ESCAPE_U7); if(!u7){ // we probably *can*, but it would be a pita; screw it - logerror("can't readline without u7\n"); + logerror("can't readline without u7"); + return NULL; + } + if(n->eof){ + logerror("already got EOF"); return NULL; } if(fprintf(n->ttyfp, "%s", prompt) < 0){ @@ -1005,15 +1009,18 @@ char* ncdirect_readline(ncdirect* n, const char* prompt){ if(ni.evtype == NCTYPE_RELEASE){ continue; } - if(id == NCKEY_EOF || id == NCKEY_ENTER){ + if(id == NCKEY_EOF || id == NCKEY_ENTER || (ncinput_ctrl_p(&ni) && id == 'd')){ if(id == NCKEY_ENTER){ if(fputc('\n', n->ttyfp) < 0){ free(str); return NULL; } - }else if(wused == 1){ // NCKEY_EOF without input returns NULL - free(str); - return NULL; + }else{ + n->eof = 1; + if(wused == 1){ // NCKEY_EOF without input returns NULL + free(str); + return NULL; + } } char* ustr = ncwcsrtombs(str); free(str); diff --git a/src/lib/in.c b/src/lib/in.c index dc0aa6084..2385538dd 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -2476,7 +2476,15 @@ int notcurses_getvec(notcurses* n, const struct timespec* absdl, } uint32_t ncdirect_get(ncdirect* n, const struct timespec* absdl, ncinput* ni){ - return internal_get(n->tcache.ictx, absdl, ni); + if(n->eof){ + logerror("already got EOF"); + return -1; + } + uint32_t r = internal_get(n->tcache.ictx, absdl, ni); + if(r == NCKEY_EOF){ + n->eof = 1; + } + return r; } int get_cursor_location(inputctx* ictx, const char* u7, unsigned* y, unsigned* x){ diff --git a/src/lib/internal.h b/src/lib/internal.h index b95462bf4..5fb4893a2 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -252,6 +252,7 @@ typedef struct ncdirect { uint16_t stylemask; // current styles uint64_t flags; // copied in ncdirect_init() from param ncsharedstats stats; // stats! not as broadly used as in notcurses + unsigned eof; // have we seen EOF on stdin? } ncdirect; // Extracellular state for a cell during the render process. There is one