From 38e5a89fb2c1e3656142119ae776644d5c7f450e Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 2 Aug 2021 22:05:45 -0400 Subject: [PATCH] microsoft terminal escape database #2014 --- src/lib/direct.c | 6 +-- src/lib/termdesc.c | 118 +++++++++++++++++++++++---------------------- 2 files changed, 64 insertions(+), 60 deletions(-) diff --git a/src/lib/direct.c b/src/lib/direct.c index d640c2980..46bd4fa3f 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -4,13 +4,13 @@ #include #include #include -#ifdef USE_READLINE -#include -#endif #include "version.h" #include "visual-details.h" #include "notcurses/direct.h" #include "internal.h" +#ifdef USE_READLINE +#include +#endif // conform to the foreground and background channels of 'channels' static int diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 70ab676c1..f1d00e881 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -149,47 +149,6 @@ query_rgb(void){ return rgb; } -static int -terminfostr(char** gseq, const char* name){ - *gseq = tigetstr(name); - if(*gseq == NULL || *gseq == (char*)-1){ - *gseq = NULL; - return -1; - } - // terminfo syntax allows a number N of milliseconds worth of pause to be - // specified using $ syntax. this is then honored by tputs(). but we don't - // use tputs(), instead preferring the much faster stdio+tiparm() (at the - // expense of terminals which do require these delays). to avoid dumping - // "$" sequences all over stdio, we chop them out. real text can follow - // them, so we continue on, copying back once out of the delay. - char* wnext = NULL; // NULL until we hit a delay, then place to write - bool indelay = false; // true iff we're in a delay section - // we consider it a delay as soon as we see '$', and the delay ends at '>' - for(char* cur = *gseq ; *cur ; ++cur){ - if(!indelay){ - // if we're not in a delay section, make sure we're not starting one, - // and otherwise copy the current character back (if necessary). - if(*cur == '$'){ - wnext = cur; - indelay = true; - }else{ - if(wnext){ - *wnext++ = *cur; - } - } - }else{ - // we are in a delay section. make sure we're not ending one. - if(*cur == '>'){ - indelay = false; - } - } - } - if(wnext){ - *wnext = '\0'; - } - return 0; -} - // we couldn't get a terminal from interrogation, so let's see if the TERM // matches any of our known terminals. this can only be as accurate as the // TERM setting is (and as up-to-date and complete as we are). @@ -260,6 +219,61 @@ compare_versions(const char* restrict v1, const char* restrict v2){ return 0; } +static inline int +terminfostr(char** gseq, const char* name){ + *gseq = tigetstr(name); + if(*gseq == NULL || *gseq == (char*)-1){ + *gseq = NULL; + return -1; + } + // terminfo syntax allows a number N of milliseconds worth of pause to be + // specified using $ syntax. this is then honored by tputs(). but we don't + // use tputs(), instead preferring the much faster stdio+tiparm() (at the + // expense of terminals which do require these delays). to avoid dumping + // "$" sequences all over stdio, we chop them out. real text can follow + // them, so we continue on, copying back once out of the delay. + char* wnext = NULL; // NULL until we hit a delay, then place to write + bool indelay = false; // true iff we're in a delay section + // we consider it a delay as soon as we see '$', and the delay ends at '>' + for(char* cur = *gseq ; *cur ; ++cur){ + if(!indelay){ + // if we're not in a delay section, make sure we're not starting one, + // and otherwise copy the current character back (if necessary). + if(*cur == '$'){ + wnext = cur; + indelay = true; + }else{ + if(wnext){ + *wnext++ = *cur; + } + } + }else{ + // we are in a delay section. make sure we're not ending one. + if(*cur == '>'){ + indelay = false; + } + } + } + if(wnext){ + *wnext = '\0'; + } + return 0; +} + +static inline int +init_terminfo_esc(tinfo* ti, const char* name, escape_e idx, + size_t* tablelen, size_t* tableused){ + char* tstr; + if(terminfostr(&tstr, name) == 0){ + if(grow_esc_table(ti, tstr, idx, tablelen, tableused)){ + return -1; + } + }else{ + ti->escindices[idx] = 0; + } + return 0; +} + // Tertiary Device Attributes, necessary to identify VTE. // https://vt100.net/docs/vt510-rm/DA3.html // Replies with DCS ! | ... ST @@ -354,20 +368,6 @@ send_initial_queries(int fd, bool minimal){ return 0; } -static int -init_terminfo_esc(tinfo* ti, const char* name, escape_e idx, - size_t* tablelen, size_t* tableused){ - char* tstr; - if(terminfostr(&tstr, name) == 0){ - if(grow_esc_table(ti, tstr, idx, tablelen, tableused)){ - return -1; - } - }else{ - ti->escindices[idx] = 0; - } - return 0; -} - // if we get a response to the standard cursor locator escape, we know this // terminal supports it, hah. static int @@ -667,8 +667,12 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, memset(ti, 0, sizeof(*ti)); #ifdef __APPLE__ qterm = macos_early_matches(termname); -#endif -#ifdef __linux__ +#elif defined(__MINGW64__) + if(prepare_windows_terminal(ti)){ + return -1; + } + qterm = TERMINAL_MSTERMINAL; +#elif defined(__linux__) ti->linux_fb_fd = -1; ti->linux_fbuffer = MAP_FAILED; // we might or might not program quadrants into the console font