Skip to content

Commit

Permalink
microsoft terminal escape database #2014
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Aug 5, 2021
1 parent 62b9319 commit 38e5a89
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
6 changes: 3 additions & 3 deletions src/lib/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#ifdef USE_READLINE
#include <readline/readline.h>
#endif
#include "version.h"
#include "visual-details.h"
#include "notcurses/direct.h"
#include "internal.h"
#ifdef USE_READLINE
#include <readline/readline.h>
#endif

// conform to the foreground and background channels of 'channels'
static int
Expand Down
118 changes: 61 additions & 57 deletions src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<N> 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
// "$<N>" 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).
Expand Down Expand Up @@ -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 $<N> 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
// "$<N>" 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 38e5a89

Please sign in to comment.