From 9746a06bdedcc1a5b4ca6e526c6aec16e47911aa Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 10 Jul 2021 21:30:19 -0400 Subject: [PATCH] prepare a cursor report queue #1692 --- src/lib/input.c | 24 +++++++++++++++--------- src/lib/stats.c | 13 ++++++------- src/lib/termdesc.h | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/lib/input.c b/src/lib/input.c index 2af3f562f..06482cb73 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -429,15 +429,21 @@ handle_queued_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin if(ni == NULL){ ni = &nireal; } - // if there was some error in getc(), we still dole out the existing queue - if(nc->inputbuf_occupied == 0){ - return -1; - } - int r = pop_input_keypress(nc); - char32_t ret = handle_getc(nc, r, ni, leftmargin, topmargin); - if(ret != (char32_t)-1){ - ni->id = ret; - } + char32_t ret; + do{ + // if there was some error in getc(), we still dole out the existing queue + if(nc->inputbuf_occupied == 0){ + return -1; + } + int r = pop_input_keypress(nc); + ret = handle_getc(nc, r, ni, leftmargin, topmargin); + if(ret != (char32_t)-1){ + ni->id = ret; + } + if(ret == NCKEY_CURSOR_LOCATION_REPORT){ + // process this internally + } + }while(ret == NCKEY_CURSOR_LOCATION_REPORT); return ret; } diff --git a/src/lib/stats.c b/src/lib/stats.c index 120111ee5..4fcb3081a 100644 --- a/src/lib/stats.c +++ b/src/lib/stats.c @@ -145,6 +145,7 @@ void notcurses_stats_reset(notcurses* nc, ncstats* stats){ stash->sprixelelisions += nc->stats.sprixelelisions; stash->sprixelbytes += nc->stats.sprixelbytes; stash->appsync_updates += nc->stats.appsync_updates; + stash->input_errors += nc->stats.input_errors; stash->fbbytes = nc->stats.fbbytes; stash->planes = nc->stats.planes; @@ -193,13 +194,11 @@ void summarize_stats(notcurses* nc){ totalbuf, minbuf, avgbuf, maxbuf); } if(stats->renders || stats->failed_renders){ - fprintf(stderr, "%ju failed render%s, %ju failed raster%s, %ju refresh%s\n", - stats->failed_renders, - stats->failed_renders == 1 ? "" : "s", - stats->failed_writeouts, - stats->failed_writeouts == 1 ? "" : "s", - stats->refreshes, - stats->refreshes == 1 ? "" : "es"); + fprintf(stderr, "%ju failed render%s, %ju failed raster%s, %ju refresh%s, %ju input error%s\n", + stats->failed_renders, stats->failed_renders == 1 ? "" : "s", + stats->failed_writeouts, stats->failed_writeouts == 1 ? "" : "s", + stats->refreshes, stats->refreshes == 1 ? "" : "es", + stats->input_errors, stats->input_errors == 1 ? "" : "s"); fprintf(stderr, "RGB emits:elides: def %ju:%ju fg %ju:%ju bg %ju:%ju\n", stats->defaultemissions, stats->defaultelisions, diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 8fcf2570f..44d59c6db 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -69,6 +69,15 @@ typedef enum { ESCAPE_MAX } escape_e; +// when we read a cursor report, we put it on the queue for internal +// processing. this is necessary since it can be arbitrarily interleaved with +// other input when stdin is connected to our terminal. these are already +// processed to be 0-based. +typedef struct cursorreport { + int x, y; + struct cursorreport* next; +} cursorreport; + // we read input from one or two places. if stdin is connected to our // controlling tty, we read only from that file descriptor. if it is // connected to something else, and we have a controlling tty, we will @@ -93,6 +102,7 @@ typedef struct ncinputlayer { // be reset (semantics are relied upon by widgets for mouse click detection). uint64_t input_events; struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys + cursorreport* creport_queue; // queue of cursor reports } ncinputlayer; // terminal interface description. most of these are acquired from terminfo(5) @@ -148,12 +158,12 @@ typedef struct tinfo { // less one times the cell height. sixel_maxy is thus recomputed whenever // we get a resize event. it is only defined if we have sixel_maxy_pristine, // so kitty graphics (which don't force a scroll) never deal with this. - int sixel_maxy; // maximum working sixel height - int sixel_maxy_pristine; // maximum theoretical sixel height, as queried + int sixel_maxy; // maximum working sixel height + int sixel_maxy_pristine; // maximum theoretical sixel height, as queried int sprixel_scale_height; // sprixel must be a multiple of this many rows const char* termname; // terminal name from environment variables/init char* termversion; // terminal version (freeform) from query responses - struct termios tpreserved; // terminal state upon entry + struct termios tpreserved;// terminal state upon entry ncinputlayer input; // input layer int default_rows; // LINES environment var / lines terminfo / 24