termdesc: move smcup/rmcup lookup into interrogate_terminfo() #1525

This commit is contained in:
nick black 2021-05-26 02:34:50 -04:00 committed by Nick Black
parent 01c4ec61f3
commit 0f10eaf9fc
4 changed files with 22 additions and 18 deletions

View File

@ -767,7 +767,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
if(ncvisual_init(NCLOGLEVEL_SILENT)){ if(ncvisual_init(NCLOGLEVEL_SILENT)){
goto err; goto err;
} }
if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8)){ if(interrogate_terminfo(&ret->tcache, ret->ctermfd, shortname_term, utf8, 1)){
goto err; goto err;
} }
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache); update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache);

View File

@ -605,11 +605,13 @@ void update_write_stats(const struct timespec* time1, const struct timespec* tim
void sigwinch_handler(int signo); void sigwinch_handler(int signo);
void init_lang(notcurses* nc); // nc may be NULL, only used for logging void init_lang(notcurses* nc); // nc may be NULL, only used for logging
int terminfostr(char** gseq, const char* name);
// load |ti| from the terminfo database, which must already have been // load |ti| from the terminfo database, which must already have been
// initialized. set |utf8| if we've verified UTF8 output encoding. // initialized. set |utf8| if we've verified UTF8 output encoding.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8); // set |noaltscreen| to inhibit alternate screen detection. |fd| ought
// be connected to a terminal device, or -1 if no terminal is available.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
unsigned utf8, unsigned noaltscreen);
void free_terminfo_cache(tinfo* ti); void free_terminfo_cache(tinfo* ti);

View File

@ -1056,7 +1056,8 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
} }
const char* shortname_term = termname(); const char* shortname_term = termname();
// const char* longname_term = longname(); // const char* longname_term = longname();
if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8)){ if(interrogate_terminfo(&ret->tcache, ret->ttyfd, shortname_term, utf8,
opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
goto err; goto err;
} }
int dimy, dimx; int dimy, dimx;
@ -1070,11 +1071,6 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
if(set_fd_nonblocking(ret->input.ttyinfd, 1, &ret->stdio_blocking_save)){ 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.
if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
terminfostr(&ret->tcache.smcup, "smcup");
terminfostr(&ret->tcache.rmcup, "rmcup");
}
if(ncvisual_init(ret->loglevel)){ if(ncvisual_init(ret->loglevel)){
goto err; goto err;
} }

View File

@ -54,11 +54,8 @@ query_rgb(void){
return rgb; return rgb;
} }
int terminfostr(char** gseq, const char* name){ static int
char* seq; terminfostr(char** gseq, const char* name){
if(gseq == NULL){
gseq = &seq;
}
*gseq = tigetstr(name); *gseq = tigetstr(name);
if(*gseq == NULL || *gseq == (char*)-1){ if(*gseq == NULL || *gseq == (char*)-1){
*gseq = NULL; *gseq = NULL;
@ -66,10 +63,13 @@ int terminfostr(char** gseq, const char* name){
} }
// terminfo syntax allows a number N of milliseconds worth of pause to be // terminfo syntax allows a number N of milliseconds worth of pause to be
// specified using $<N> syntax. this is then honored by tputs(). but we don't // specified using $<N> syntax. this is then honored by tputs(). but we don't
// use tputs(), instead preferring the much faster stdio+tiparm(). to avoid // use tputs(), instead preferring the much faster stdio+tiparm() (at the
// dumping "$<N>" sequences all over stdio, we chop them out. // expense of terminals which do require these delays). to avoid dumping
// "$<N>" sequences all over stdio, we chop them out.
char* pause; char* pause;
if( (pause = strchr(*gseq, '$')) ){ if( (pause = strchr(*gseq, '$')) ){
// FIXME can there ever be further content following a pause?
// tighten this up to match the precise spec in terminfo(5)!
*pause = '\0'; *pause = '\0';
} }
return 0; return 0;
@ -140,7 +140,8 @@ void free_terminfo_cache(tinfo* ti){
// termname is just the TERM environment variable. some details are not // termname is just the TERM environment variable. some details are not
// exposed via terminfo, and we must make heuristic decisions based on // exposed via terminfo, and we must make heuristic decisions based on
// the detected terminal type, yuck :/. // the detected terminal type, yuck :/.
int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8){ int interrogate_terminfo(tinfo* ti, int fd, const char* termname,
unsigned utf8, unsigned noaltscreen){
memset(ti, 0, sizeof(*ti)); memset(ti, 0, sizeof(*ti));
ti->utf8 = utf8; ti->utf8 = utf8;
// allow the "rgb" boolean terminfo capability, a COLORTERM environment // allow the "rgb" boolean terminfo capability, a COLORTERM environment
@ -162,12 +163,17 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8)
ti->CCCflag = false; ti->CCCflag = false;
} }
} }
// check that the terminal provides cursor addressing (absolute movement) // verify that the terminal provides cursor addressing (absolute movement)
terminfostr(&ti->cup, "cup"); terminfostr(&ti->cup, "cup");
if(ti->cup == NULL){ if(ti->cup == NULL){
fprintf(stderr, "Required terminfo capability 'cup' not defined\n"); fprintf(stderr, "Required terminfo capability 'cup' not defined\n");
return -1; return -1;
} }
// neither of these is supported on e.g. the "linux" virtual console.
if(!noaltscreen){
terminfostr(&ti->smcup, "smcup");
terminfostr(&ti->rmcup, "rmcup");
}
// check that the terminal provides automatic margins // check that the terminal provides automatic margins
ti->AMflag = tigetflag("am") == 1; ti->AMflag = tigetflag("am") == 1;
if(!ti->AMflag){ if(!ti->AMflag){