From f9b88c50794a950da7d8399dc125fc27e4dc79d0 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 23 Nov 2019 20:39:22 -0500 Subject: [PATCH] implement notcurses_palette_size() --- include/notcurses.h | 4 ++-- src/bin/demo.c | 1 + src/lib/notcurses.c | 12 +++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/notcurses.h b/include/notcurses.h index 895e625f9..1595e2847 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -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. unsigned notcurses_supported_styles(const struct notcurses* nc); -// Returns the number of colors supported by the palette, or 0 if there is no -// palette (DirectColor or no colors). +// Returns the number of colors supported by the palette, or 1 if there is no +// color support. int notcurses_palette_size(const struct notcurses* nc); // Working with cells diff --git a/src/bin/demo.c b/src/bin/demo.c index e61345484..0afd424c4 100644 --- a/src/bin/demo.c +++ b/src/bin/demo.c @@ -25,6 +25,7 @@ int main(void){ fprintf(stderr, "Couldn't get standard plane\n"); goto err; } + sleep(1); int x, y, rows, cols; ncplane_dimyx(ncp, &rows, &cols); cell c; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 0242e1ccf..49bafa23a 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -265,7 +265,7 @@ interrogate_terminfo(notcurses* nc, const notcurses_options* opts){ nc->RGBflag = tigetflag("RGB") == 1; if((nc->colors = tigetnum("colors")) <= 0){ 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)){ fprintf(stderr, "Warning: advertised RGB flag but only %d colors\n", 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){ if(simple_gcluster_p(gcluster)){ c->gcluster = *gcluster; -fprintf(stderr, "SIMPLE! %c %d\n", c->gcluster, !!c->gcluster); return !!c->gcluster; } const char* end = gcluster + 1; while(*(const unsigned char*)end >= 0x80){ // FIXME broken broken broken ++end; } -fprintf(stderr, "END: %p G: %p DIFF: %zu %s\n", end, gcluster, end - gcluster, gcluster); // FIXME enlarge pool on demand memcpy(n->pool + n->poolwrite, gcluster, end - gcluster); 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)); int wcs = 0; while(*gcluster){ -fprintf(stderr, "wcs: %d gcluster: %s ret: %d\n", wcs, gcluster, ret); wcs = cell_load(n, &c, gcluster); if(wcs < 0){ return -ret; @@ -667,17 +664,14 @@ fprintf(stderr, "wcs: %d gcluster: %s ret: %d\n", wcs, gcluster, ret); } wcs = ncplane_putc(n, &c, gcluster); if(wcs < 0){ -fprintf(stderr, "wcsnew: %d\n", wcs); return -ret; } if(wcs == 0){ break; } -fprintf(stderr, "wcsnew: %d\n", wcs); gcluster += wcs; ret += wcs; } -fprintf(stderr, "RETURNING %d\n", ret); return ret; } @@ -692,3 +686,7 @@ unsigned notcurses_supported_styles(const notcurses* nc){ styles |= nc->italics ? WA_ITALIC : 0; return styles; } + +int notcurses_palette_size(const notcurses* nc){ + return nc->colors; +}