implement notcurses_palette_size()

pull/15/head
nick black 5 years ago
parent a509cb6320
commit f9b88c5079
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -204,8 +204,8 @@ int ncplane_bg_rgb8(struct ncplane* n, int r, int g, int b);
// if the terminal can support it together with color. // if the terminal can support it together with color.
unsigned notcurses_supported_styles(const struct notcurses* nc); unsigned notcurses_supported_styles(const struct notcurses* nc);
// Returns the number of colors supported by the palette, or 0 if there is no // Returns the number of colors supported by the palette, or 1 if there is no
// palette (DirectColor or no colors). // color support.
int notcurses_palette_size(const struct notcurses* nc); int notcurses_palette_size(const struct notcurses* nc);
// Working with cells // Working with cells

@ -25,6 +25,7 @@ int main(void){
fprintf(stderr, "Couldn't get standard plane\n"); fprintf(stderr, "Couldn't get standard plane\n");
goto err; goto err;
} }
sleep(1);
int x, y, rows, cols; int x, y, rows, cols;
ncplane_dimyx(ncp, &rows, &cols); ncplane_dimyx(ncp, &rows, &cols);
cell c; cell c;

@ -265,7 +265,7 @@ interrogate_terminfo(notcurses* nc, const notcurses_options* opts){
nc->RGBflag = tigetflag("RGB") == 1; nc->RGBflag = tigetflag("RGB") == 1;
if((nc->colors = tigetnum("colors")) <= 0){ if((nc->colors = tigetnum("colors")) <= 0){
fprintf(stderr, "This terminal doesn't appear to support colors\n"); fprintf(stderr, "This terminal doesn't appear to support colors\n");
return -1; nc->colors = 1;
}else if(nc->RGBflag && (unsigned)nc->colors < (1u << 23u)){ }else if(nc->RGBflag && (unsigned)nc->colors < (1u << 23u)){
fprintf(stderr, "Warning: advertised RGB flag but only %d colors\n", fprintf(stderr, "Warning: advertised RGB flag but only %d colors\n",
nc->colors); nc->colors);
@ -630,14 +630,12 @@ int ncplane_putc(ncplane* n, const cell* c, const char* gclust){
int cell_load(ncplane* n, cell* c, const char* gcluster){ int cell_load(ncplane* n, cell* c, const char* gcluster){
if(simple_gcluster_p(gcluster)){ if(simple_gcluster_p(gcluster)){
c->gcluster = *gcluster; c->gcluster = *gcluster;
fprintf(stderr, "SIMPLE! %c %d\n", c->gcluster, !!c->gcluster);
return !!c->gcluster; return !!c->gcluster;
} }
const char* end = gcluster + 1; const char* end = gcluster + 1;
while(*(const unsigned char*)end >= 0x80){ // FIXME broken broken broken while(*(const unsigned char*)end >= 0x80){ // FIXME broken broken broken
++end; ++end;
} }
fprintf(stderr, "END: %p G: %p DIFF: %zu %s\n", end, gcluster, end - gcluster, gcluster);
// FIXME enlarge pool on demand // FIXME enlarge pool on demand
memcpy(n->pool + n->poolwrite, gcluster, end - gcluster); memcpy(n->pool + n->poolwrite, gcluster, end - gcluster);
c->gcluster = n->poolwrite + 0x80; c->gcluster = n->poolwrite + 0x80;
@ -657,7 +655,6 @@ int ncplane_putstr(ncplane* n, const char* gcluster){
cell_set_bg(&c, cell_rgb_red(rgb), cell_rgb_green(rgb), cell_rgb_blue(rgb)); cell_set_bg(&c, cell_rgb_red(rgb), cell_rgb_green(rgb), cell_rgb_blue(rgb));
int wcs = 0; int wcs = 0;
while(*gcluster){ while(*gcluster){
fprintf(stderr, "wcs: %d gcluster: %s ret: %d\n", wcs, gcluster, ret);
wcs = cell_load(n, &c, gcluster); wcs = cell_load(n, &c, gcluster);
if(wcs < 0){ if(wcs < 0){
return -ret; return -ret;
@ -667,17 +664,14 @@ fprintf(stderr, "wcs: %d gcluster: %s ret: %d\n", wcs, gcluster, ret);
} }
wcs = ncplane_putc(n, &c, gcluster); wcs = ncplane_putc(n, &c, gcluster);
if(wcs < 0){ if(wcs < 0){
fprintf(stderr, "wcsnew: %d\n", wcs);
return -ret; return -ret;
} }
if(wcs == 0){ if(wcs == 0){
break; break;
} }
fprintf(stderr, "wcsnew: %d\n", wcs);
gcluster += wcs; gcluster += wcs;
ret += wcs; ret += wcs;
} }
fprintf(stderr, "RETURNING %d\n", ret);
return ret; return ret;
} }
@ -692,3 +686,7 @@ unsigned notcurses_supported_styles(const notcurses* nc){
styles |= nc->italics ? WA_ITALIC : 0; styles |= nc->italics ? WA_ITALIC : 0;
return styles; return styles;
} }
int notcurses_palette_size(const notcurses* nc){
return nc->colors;
}

Loading…
Cancel
Save