From 57e418284e9cf7ab7e3706a963ac430cf13bf514 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 20 Jun 2021 04:47:24 -0400 Subject: [PATCH] add ESCAPE_BSU/ESU, clean up query_state #1582 --- src/lib/input.c | 33 +++++++++++++++------------------ src/lib/termdesc.h | 4 ++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/lib/input.c b/src/lib/input.c index 534128949..78bc1412e 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -647,7 +647,7 @@ typedef enum { STATE_XTSMGRAPHICS_DRAIN, // drain out XTSMGRAPHICS to 'S' } initstates_e; -typedef struct init_state { +typedef struct query_state { tinfo* tcache; queried_terminals_e qterm; // discovered terminal initstates_e state, stringstate; @@ -658,7 +658,7 @@ typedef struct init_state { size_t stridx; // position to write in string uint32_t bg; // queried default background or 0 bool xtgettcap_good; // high when we've received DCS 1 -} init_state; +} query_state; static int ruts_numeric(int* numeric, unsigned char c){ @@ -699,7 +699,7 @@ ruts_hex(int* numeric, unsigned char c){ // add a decoded hex byte to the string static int -ruts_string(init_state* inits, initstates_e state){ +ruts_string(query_state* inits, initstates_e state){ if(inits->stridx == sizeof(inits->runstring)){ return -1; // overflow, too long } @@ -717,7 +717,7 @@ ruts_string(init_state* inits, initstates_e state){ } static int -stash_string(init_state* inits){ +stash_string(query_state* inits){ //fprintf(stderr, "string terminator after %d [%s]\n", inits->stringstate, inits->runstring); switch(inits->stringstate){ case STATE_XTVERSION1:{ @@ -771,7 +771,7 @@ stash_string(init_state* inits){ // returns 1 after handling the Device Attributes response, 0 if more input // ought be fed to the machine, and -1 on an invalid state transition. static int -pump_control_read(init_state* inits, unsigned char c){ +pump_control_read(query_state* inits, unsigned char c){ //fprintf(stderr, "state: %2d char: %1c %3d %02x\n", inits->state, isprint(c) ? c : ' ', c, c); if(c == NCKEY_ESC){ inits->state = STATE_ESC; @@ -1071,26 +1071,18 @@ pump_control_read(init_state* inits, unsigned char c){ // complete the terminal detection process static int -control_read(tinfo* tcache, int ttyfd, queried_terminals_e* detected, uint32_t* bg){ - init_state inits = { - .tcache = tcache, - .state = STATE_NULL, - .qterm = TERMINAL_UNKNOWN, - }; +control_read(int ttyfd, query_state* qstate){ unsigned char* buf; ssize_t s; - *detected = TERMINAL_UNKNOWN; if((buf = malloc(BUFSIZ)) == NULL){ return -1; } while((s = read(ttyfd, buf, BUFSIZ)) != -1){ for(ssize_t idx = 0; idx < s ; ++idx){ - int r = pump_control_read(&inits, buf[idx]); + int r = pump_control_read(qstate, buf[idx]); if(r == 1){ // success! free(buf); - *detected = inits.qterm; - *bg = inits.bg; //fprintf(stderr, "at end, derived terminal %d\n", inits.qterm); return 0; }else if(r < 0){ @@ -1119,12 +1111,17 @@ int ncinputlayer_init(tinfo* tcache, FILE* infp, queried_terminals_e* detected){ nilayer->input_events = 0; int csifd = nilayer->ttyfd >= 0 ? nilayer->ttyfd : nilayer->infd; if(isatty(csifd)){ - uint32_t bg; - if(control_read(tcache, csifd, detected, &bg)){ + query_state inits = { + .tcache = tcache, + .state = STATE_NULL, + .qterm = TERMINAL_UNKNOWN, + }; + if(control_read(csifd, &inits)){ input_free_esctrie(&nilayer->inputescapes); return -1; } - tcache->bg_collides_default = bg; + tcache->bg_collides_default = inits.bg; + *detected = inits.qterm; } return 0; } diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index fbbf2802a..418a52c91 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -61,6 +61,10 @@ typedef enum { ESCAPE_INITC, // "initc" set up palette entry ESCAPE_GETM, // "getm" get mouse events ESCAPE_DSRCPR, // "u7" cursor position report + // Application synchronized updates, not present in terminfo + // (https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec) + ESCAPE_BSU, // Begin Synchronized Update + ESCAPE_ESU, // End Synchronized Update ESCAPE_MAX } escape_e;