From 0e6f52533bce984e67fcf1c82a33ebf49b4b2eb2 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 17 Jun 2021 16:37:50 -0400 Subject: [PATCH] introduce nccapabilites struct, move utf8/ccc therein #1768 --- src/lib/blit.c | 2 +- src/lib/blitset.h | 2 +- src/lib/debug.c | 6 +++--- src/lib/direct.c | 2 +- src/lib/fade.c | 4 ++-- src/lib/notcurses.c | 16 ++++++++-------- src/lib/render.c | 2 +- src/lib/termdesc.c | 4 ++-- src/lib/termdesc.h | 12 ++++++++---- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/lib/blit.c b/src/lib/blit.c index 9cb0282fd..c0f8a7987 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -966,7 +966,7 @@ const struct blitset* lookup_blitset(const tinfo* tcache, ncblitter_e setid, boo } } // the only viable blitters in ASCII are NCBLIT_1x1 and NCBLIT_PIXEL - if(!tcache->utf8 && (setid != NCBLIT_1x1 && setid != NCBLIT_PIXEL)){ + if(!tcache->caps.utf8 && (setid != NCBLIT_1x1 && setid != NCBLIT_PIXEL)){ if(may_degrade){ setid = NCBLIT_1x1; }else{ diff --git a/src/lib/blitset.h b/src/lib/blitset.h index af241208c..c1ec0fed8 100644 --- a/src/lib/blitset.h +++ b/src/lib/blitset.h @@ -25,7 +25,7 @@ encoding_x_scale(const tinfo* tcache, const struct blitset* bset) { // use NCBLIT_PIXEL for NCBLIT_DEFAULT, though maybe this ought change. static inline ncblitter_e rgba_blitter_default(const tinfo* tcache, ncscale_e scale){ - if(!tcache->utf8){ + if(!tcache->caps.utf8){ return NCBLIT_1x1; // only one that works in ASCII } if(scale == NCSCALE_NONE || scale == NCSCALE_SCALE){ diff --git a/src/lib/debug.c b/src/lib/debug.c index 2c33b1b8a..0279ac6ee 100644 --- a/src/lib/debug.c +++ b/src/lib/debug.c @@ -15,7 +15,7 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols, unsigned images, unsigned videos){ const char indent[] = " "; fprintf(debugfp, "%scolors: %u rgb: %c ccc: %c setaf: %c setab: %c\n", - indent, ti->colors, capbool(ti->RGBflag), capbool(ti->CCCflag), + indent, ti->colors, capbool(ti->RGBflag), capbool(ti->caps.can_change_colors), capyn(get_escape(ti, ESCAPE_SETAF)), capyn(get_escape(ti, ESCAPE_SETAB))); fprintf(debugfp, "%ssgr: %c sgr0: %c op: %c fgop: %c bgop: %c\n", @@ -37,10 +37,10 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols, fprintf(debugfp, "%srgba pixel graphics supported\n", indent); } fprintf(debugfp, "%sutf8: %c quad: %c sex: %c braille: %c images: %c videos: %c\n", - indent, capbool(ti->utf8), capbool(ti->quadrants), + indent, capbool(ti->caps.utf8), capbool(ti->quadrants), capbool(ti->sextants), capbool(ti->braille), capbool(images), capbool(videos)); - if(ti->utf8){ + if(ti->caps.utf8){ fprintf(debugfp, "%s{%ls} {%ls} ⎧%.122ls⎫ ⎧%.6ls%.3ls⎫ ⎧%.6ls%.3ls⎫ ⎧█ ⎫ 🯰🯱\n", indent, get_blitter_egcs(NCBLIT_2x1), get_blitter_egcs(NCBLIT_2x2), get_blitter_egcs(NCBLIT_3x2), diff --git a/src/lib/direct.c b/src/lib/direct.c index 09d16c8d9..8d476a886 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -1270,7 +1270,7 @@ bool ncdirect_canopen_images(const ncdirect* n __attribute__ ((unused))){ // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. bool ncdirect_canutf8(const ncdirect* n){ - return n->tcache.utf8; + return n->tcache.caps.utf8; } int ncdirect_flush(const ncdirect* nc){ diff --git a/src/lib/fade.c b/src/lib/fade.c index f5b842b34..ededc5591 100644 --- a/src/lib/fade.c +++ b/src/lib/fade.c @@ -233,7 +233,7 @@ int ncplane_fadeout_iteration(ncplane* n, ncfadectx* nctx, int iter, static ncfadectx* ncfadectx_setup_internal(ncplane* n, const struct timespec* ts){ if(!ncplane_notcurses(n)->tcache.RGBflag && - !ncplane_notcurses(n)->tcache.CCCflag){ // terminal can't fade + !ncplane_notcurses(n)->tcache.caps.can_change_colors){ // terminal can't fade return NULL; } ncfadectx* nctx = malloc(sizeof(*nctx)); @@ -302,7 +302,7 @@ int ncplane_pulse(ncplane* n, const struct timespec* ts, fadecb fader, void* cur ncfadectx pp; int ret; if(!ncplane_notcurses(n)->tcache.RGBflag && - !ncplane_notcurses(n)->tcache.CCCflag){ // terminal can't fade + !ncplane_notcurses(n)->tcache.caps.can_change_colors){ // terminal can't fade return -1; } if(alloc_ncplane_palette(n, &pp, ts)){ diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 908ac9c99..d57075586 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -837,7 +837,7 @@ init_banner_warnings(const notcurses* nc, FILE* out){ fprintf(out, "\n Warning! Colors subject to https://github.com/dankamongmen/notcurses/issues/4"); fprintf(out, "\n Specify a (correct) TrueColor TERM, or COLORTERM=24bit.\n"); }else{ - if(!nc->tcache.CCCflag){ + if(!nc->tcache.caps.can_change_colors){ fprintf(out, "\n Warning! Advertised TrueColor but no 'ccc' flag\n"); } } @@ -2126,31 +2126,31 @@ int notcurses_mouse_disable(notcurses* n){ } bool notcurses_canutf8(const notcurses* nc){ - return nc->tcache.utf8; + return nc->tcache.caps.utf8; } bool notcurses_canhalfblock(const notcurses* nc){ - return nc->tcache.utf8; + return nc->tcache.caps.utf8; } bool notcurses_canquadrant(const notcurses* nc){ - return nc->tcache.quadrants && nc->tcache.utf8; + return nc->tcache.quadrants && nc->tcache.caps.utf8; } bool notcurses_cansextant(const notcurses* nc){ - return nc->tcache.sextants && nc->tcache.utf8; + return nc->tcache.sextants && nc->tcache.caps.utf8; } bool notcurses_canbraille(const notcurses* nc){ - return nc->tcache.braille && nc->tcache.utf8; + return nc->tcache.braille && nc->tcache.caps.utf8; } bool notcurses_canfade(const notcurses* nc){ - return nc->tcache.CCCflag || nc->tcache.RGBflag; + return nc->tcache.caps.can_change_colors || nc->tcache.RGBflag; } bool notcurses_canchangecolor(const notcurses* nc){ - if(!nc->tcache.CCCflag){ + if(!nc->tcache.caps.can_change_colors){ return false; } ncpalette* p; diff --git a/src/lib/render.c b/src/lib/render.c index cc79b11a1..f847d09da 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -758,7 +758,7 @@ int term_fg_rgb8(const tinfo* ti, FILE* out, unsigned r, unsigned g, unsigned b) static inline int update_palette(notcurses* nc, FILE* out){ - if(nc->tcache.CCCflag){ + if(nc->tcache.caps.can_change_colors){ const char* initc = get_escape(&nc->tcache, ESCAPE_INITC); for(size_t damageidx = 0 ; damageidx < sizeof(nc->palette.chans) / sizeof(*nc->palette.chans) ; ++damageidx){ unsigned r, g, b; diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 62dfcea84..48cd27c6d 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -266,7 +266,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, return -1; } } - ti->utf8 = utf8; + ti->caps.utf8 = utf8; // allow the "rgb" boolean terminfo capability, a COLORTERM environment // variable of either "truecolor" or "24bit", or unconditionally enable it // for several terminals known to always support 8bpc rgb setaf/setab. @@ -328,7 +328,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, if(colors){ const char* initc = get_escape(ti, ESCAPE_INITC); if(initc){ - ti->CCCflag = tigetflag("ccc") == 1; + ti->caps.can_change_colors = tigetflag("ccc") == 1; } }else{ // disable initc if there's no color support ti->escindices[ESCAPE_INITC] = 0; diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index d3a4e92d3..bca1eaa0b 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -86,6 +86,13 @@ typedef struct ncinputlayer { struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys } ncinputlayer; +// terminal capabilities exported to the user +typedef struct nccapabilities { + // assigned based off nl_langinfo() in notcurses_core_init() + bool utf8; // are we using utf-8 encoding? from nl_langinfo(3) + bool can_change_colors; // can we change the palette? terminfo ccc capability +} nccapabilities; + // terminal interface description. most of these are acquired from terminfo(5) // (using a database entry specified by TERM). some are determined via // heuristics based off terminal interrogation or the TERM environment @@ -94,6 +101,7 @@ typedef struct ncinputlayer { typedef struct tinfo { uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable char* esctable; // packed table of escape sequences + nccapabilities caps; // exported to the user, when requested unsigned colors;// number of colors terminfo reported usable for this screen // we use the cell's size in pixels for pixel blitting. this information can // be acquired on all terminals with pixel support. @@ -133,13 +141,9 @@ typedef struct tinfo { bool bitmap_supported; // do we support bitmaps (post pixel_query_done)? bool bitmap_lowest_line; // can we render pixels to the bottom row? bool RGBflag; // "RGB" flag for 24bpc truecolor - bool CCCflag; // "CCC" flag for palette set capability bool BCEflag; // "BCE" flag for erases with background color bool AMflag; // "AM" flag for automatic movement to next line - // assigned based off nl_langinfo() in notcurses_core_init() - bool utf8; // are we using utf-8 encoding, as hoped? - // these are assigned wholly through TERM-based heuristics bool quadrants; // do we have (good, vetted) Unicode 1 quadrant support? bool sextants; // do we have (good, vetted) Unicode 13 sextant support?