introduce nccapabilites struct, move utf8/ccc therein #1768

This commit is contained in:
nick black 2021-06-17 16:37:50 -04:00 committed by Nick Black
parent 7eedc7714d
commit 0e6f52533b
9 changed files with 27 additions and 23 deletions

View File

@ -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 // 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){ if(may_degrade){
setid = NCBLIT_1x1; setid = NCBLIT_1x1;
}else{ }else{

View File

@ -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. // use NCBLIT_PIXEL for NCBLIT_DEFAULT, though maybe this ought change.
static inline ncblitter_e static inline ncblitter_e
rgba_blitter_default(const tinfo* tcache, ncscale_e scale){ 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 return NCBLIT_1x1; // only one that works in ASCII
} }
if(scale == NCSCALE_NONE || scale == NCSCALE_SCALE){ if(scale == NCSCALE_NONE || scale == NCSCALE_SCALE){

View File

@ -15,7 +15,7 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols,
unsigned images, unsigned videos){ unsigned images, unsigned videos){
const char indent[] = " "; const char indent[] = " ";
fprintf(debugfp, "%scolors: %u rgb: %c ccc: %c setaf: %c setab: %c\n", 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_SETAF)),
capyn(get_escape(ti, ESCAPE_SETAB))); capyn(get_escape(ti, ESCAPE_SETAB)));
fprintf(debugfp, "%ssgr: %c sgr0: %c op: %c fgop: %c bgop: %c\n", 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, "%srgba pixel graphics supported\n", indent);
} }
fprintf(debugfp, "%sutf8: %c quad: %c sex: %c braille: %c images: %c videos: %c\n", 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(ti->sextants), capbool(ti->braille),
capbool(images), capbool(videos)); capbool(images), capbool(videos));
if(ti->utf8){ if(ti->caps.utf8){
fprintf(debugfp, "%s{%ls} {%ls} ⎧%.122ls⎫ ⎧%.6ls%.3ls⎫ ⎧%.6ls%.3ls⎫ ⎧█ ⎫ 🯰🯱\n", indent, 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_2x1), get_blitter_egcs(NCBLIT_2x2),
get_blitter_egcs(NCBLIT_3x2), get_blitter_egcs(NCBLIT_3x2),

View File

@ -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. // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
bool ncdirect_canutf8(const ncdirect* n){ bool ncdirect_canutf8(const ncdirect* n){
return n->tcache.utf8; return n->tcache.caps.utf8;
} }
int ncdirect_flush(const ncdirect* nc){ int ncdirect_flush(const ncdirect* nc){

View File

@ -233,7 +233,7 @@ int ncplane_fadeout_iteration(ncplane* n, ncfadectx* nctx, int iter,
static ncfadectx* static ncfadectx*
ncfadectx_setup_internal(ncplane* n, const struct timespec* ts){ ncfadectx_setup_internal(ncplane* n, const struct timespec* ts){
if(!ncplane_notcurses(n)->tcache.RGBflag && 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; return NULL;
} }
ncfadectx* nctx = malloc(sizeof(*nctx)); ncfadectx* nctx = malloc(sizeof(*nctx));
@ -302,7 +302,7 @@ int ncplane_pulse(ncplane* n, const struct timespec* ts, fadecb fader, void* cur
ncfadectx pp; ncfadectx pp;
int ret; int ret;
if(!ncplane_notcurses(n)->tcache.RGBflag && 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; return -1;
} }
if(alloc_ncplane_palette(n, &pp, ts)){ if(alloc_ncplane_palette(n, &pp, ts)){

View File

@ -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 Warning! Colors subject to https://github.com/dankamongmen/notcurses/issues/4");
fprintf(out, "\n Specify a (correct) TrueColor TERM, or COLORTERM=24bit.\n"); fprintf(out, "\n Specify a (correct) TrueColor TERM, or COLORTERM=24bit.\n");
}else{ }else{
if(!nc->tcache.CCCflag){ if(!nc->tcache.caps.can_change_colors){
fprintf(out, "\n Warning! Advertised TrueColor but no 'ccc' flag\n"); 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){ bool notcurses_canutf8(const notcurses* nc){
return nc->tcache.utf8; return nc->tcache.caps.utf8;
} }
bool notcurses_canhalfblock(const notcurses* nc){ bool notcurses_canhalfblock(const notcurses* nc){
return nc->tcache.utf8; return nc->tcache.caps.utf8;
} }
bool notcurses_canquadrant(const notcurses* nc){ 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){ 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){ 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){ 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){ bool notcurses_canchangecolor(const notcurses* nc){
if(!nc->tcache.CCCflag){ if(!nc->tcache.caps.can_change_colors){
return false; return false;
} }
ncpalette* p; ncpalette* p;

View File

@ -758,7 +758,7 @@ int term_fg_rgb8(const tinfo* ti, FILE* out, unsigned r, unsigned g, unsigned b)
static inline int static inline int
update_palette(notcurses* nc, FILE* out){ 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); const char* initc = get_escape(&nc->tcache, ESCAPE_INITC);
for(size_t damageidx = 0 ; damageidx < sizeof(nc->palette.chans) / sizeof(*nc->palette.chans) ; ++damageidx){ for(size_t damageidx = 0 ; damageidx < sizeof(nc->palette.chans) / sizeof(*nc->palette.chans) ; ++damageidx){
unsigned r, g, b; unsigned r, g, b;

View File

@ -266,7 +266,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
return -1; return -1;
} }
} }
ti->utf8 = utf8; ti->caps.utf8 = utf8;
// allow the "rgb" boolean terminfo capability, a COLORTERM environment // allow the "rgb" boolean terminfo capability, a COLORTERM environment
// variable of either "truecolor" or "24bit", or unconditionally enable it // variable of either "truecolor" or "24bit", or unconditionally enable it
// for several terminals known to always support 8bpc rgb setaf/setab. // 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){ if(colors){
const char* initc = get_escape(ti, ESCAPE_INITC); const char* initc = get_escape(ti, ESCAPE_INITC);
if(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 }else{ // disable initc if there's no color support
ti->escindices[ESCAPE_INITC] = 0; ti->escindices[ESCAPE_INITC] = 0;

View File

@ -86,6 +86,13 @@ typedef struct ncinputlayer {
struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys
} ncinputlayer; } 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) // terminal interface description. most of these are acquired from terminfo(5)
// (using a database entry specified by TERM). some are determined via // (using a database entry specified by TERM). some are determined via
// heuristics based off terminal interrogation or the TERM environment // heuristics based off terminal interrogation or the TERM environment
@ -94,6 +101,7 @@ typedef struct ncinputlayer {
typedef struct tinfo { typedef struct tinfo {
uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable uint16_t escindices[ESCAPE_MAX]; // table of 1-biased indices into esctable
char* esctable; // packed table of escape sequences 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 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 // we use the cell's size in pixels for pixel blitting. this information can
// be acquired on all terminals with pixel support. // 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_supported; // do we support bitmaps (post pixel_query_done)?
bool bitmap_lowest_line; // can we render pixels to the bottom row? bool bitmap_lowest_line; // can we render pixels to the bottom row?
bool RGBflag; // "RGB" flag for 24bpc truecolor 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 BCEflag; // "BCE" flag for erases with background color
bool AMflag; // "AM" flag for automatic movement to next line 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 // these are assigned wholly through TERM-based heuristics
bool quadrants; // do we have (good, vetted) Unicode 1 quadrant support? bool quadrants; // do we have (good, vetted) Unicode 1 quadrant support?
bool sextants; // do we have (good, vetted) Unicode 13 sextant support? bool sextants; // do we have (good, vetted) Unicode 13 sextant support?