From be1356d2139ac1ec508b92175eabcec9527eaa6e Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 13 Jun 2021 16:22:02 -0400 Subject: [PATCH] termdesc: use cbreak mode until interrogation is complete #1469 --- src/lib/termdesc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 3666ae920..c5d2e653f 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -241,13 +241,13 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, fprintf(stderr, "Couldn't preserve terminal state for %d (%s)\n", fd, strerror(errno)); return -1; } - } - ti->utf8 = utf8; - if(!nocbreak){ + // enter cbreak mode regardless of user preference until we've performed + // terminal interrogation. at that point, we might restore original mode. if(cbreak_mode(fd, &ti->tpreserved)){ return -1; } } + ti->utf8 = utf8; // allow the "rgb" boolean terminfo capability, a COLORTERM environment // variable of either "truecolor" or "24bit", or unconditionally enable it // for several terminals known to always support 8bpc rgb setaf/setab. @@ -405,6 +405,11 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, if(ti->color_registers >= 64){ setup_sixel_bitmaps(ti); } + if(!nocbreak){ + if(tcsetattr(fd, TCSANOW, &ti->tpreserved)){ + return -1; + } + } if(apply_term_heuristics(ti, termname, fd)){ goto err; }