From f9eed1c4121f7642556576ac124139570a2ed650 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 00:27:27 -0400 Subject: [PATCH] palette_size is unsigned #891 --- USAGE.md | 2 +- doc/man/man3/notcurses_directmode.3.md | 2 +- include/ncpp/Direct.hh | 2 +- include/ncpp/NotCurses.hh | 2 +- include/notcurses/direct.h | 2 +- include/notcurses/notcurses.h | 2 +- src/lib/direct.cpp | 2 +- src/lib/internal.h | 2 +- src/lib/notcurses.c | 2 +- src/lib/terminfo.c | 4 +++- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/USAGE.md b/USAGE.md index c81d3f13f..87a4a31c7 100644 --- a/USAGE.md +++ b/USAGE.md @@ -240,7 +240,7 @@ unsigned notcurses_supported_styles(const struct notcurses* nc); // Returns the number of simultaneous colors claimed to be supported, or 1 if // there is no color support. Note that several terminal emulators advertise // more colors than they actually support, downsampling internally. -int notcurses_palette_size(const struct notcurses* nc); +unsigned notcurses_palette_size(const struct notcurses* nc); // Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability. bool notcurses_canfade(const struct notcurses* nc); diff --git a/doc/man/man3/notcurses_directmode.3.md b/doc/man/man3/notcurses_directmode.3.md index 0e7e9115f..d78ad3af3 100644 --- a/doc/man/man3/notcurses_directmode.3.md +++ b/doc/man/man3/notcurses_directmode.3.md @@ -12,7 +12,7 @@ ncdirect_init - minimal notcurses instances for styling text **struct ncdirect* ncdirect_init(const char* termtype, FILE* fp);** -**int ncdirect_palette_size(const struct ncdirect* nc);** +**unsigned ncdirect_palette_size(const struct ncdirect* nc);** **int ncdirect_bg_rgb8(struct ncdirect* nc, unsigned r, unsigned g, unsigned b);** diff --git a/include/ncpp/Direct.hh b/include/ncpp/Direct.hh index 6a595efb0..5017ea669 100644 --- a/include/ncpp/Direct.hh +++ b/include/ncpp/Direct.hh @@ -83,7 +83,7 @@ namespace ncpp return error_guard (ncdirect_dim_y (direct), -1); } - int get_palette_size () const noexcept + unsigned get_palette_size () const noexcept { return ncdirect_palette_size (direct); } diff --git a/include/ncpp/NotCurses.hh b/include/ncpp/NotCurses.hh index e81da057c..2847b9c62 100644 --- a/include/ncpp/NotCurses.hh +++ b/include/ncpp/NotCurses.hh @@ -205,7 +205,7 @@ namespace ncpp return refresh (&rows, &cols); } - int get_palette_size () const noexcept + unsigned get_palette_size () const noexcept { return notcurses_palette_size (static_cast (nc)); } diff --git a/include/notcurses/direct.h b/include/notcurses/direct.h index 5acace54e..b32953fc6 100644 --- a/include/notcurses/direct.h +++ b/include/notcurses/direct.h @@ -29,7 +29,7 @@ API int ncdirect_bg_palindex(struct ncdirect* nc, int pidx); // Returns the number of simultaneous colors claimed to be supported, or 1 if // there is no color support. Note that several terminal emulators advertise // more colors than they actually support, downsampling internally. -API int ncdirect_palette_size(const struct ncdirect* nc); +API unsigned ncdirect_palette_size(const struct ncdirect* nc); // Output the string |utf8| according to the channels |channels|. API int ncdirect_putstr(struct ncdirect* nc, uint64_t channels, const char* utf8); diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 2c0e823e9..1ace5f78a 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1052,7 +1052,7 @@ API unsigned notcurses_supported_styles(const struct notcurses* nc); // Returns the number of simultaneous colors claimed to be supported, or 1 if // there is no color support. Note that several terminal emulators advertise // more colors than they actually support, downsampling internally. -API int notcurses_palette_size(const struct notcurses* nc); +API unsigned notcurses_palette_size(const struct notcurses* nc); // Can we directly specify RGB values per cell, or only use palettes? API bool notcurses_cantruecolor(const struct notcurses* nc); diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index 31dd6ec4b..b26e29c71 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -537,7 +537,7 @@ int ncdirect_styles_set(ncdirect* n, unsigned stylebits){ return -1; } -int ncdirect_palette_size(const ncdirect* nc){ +unsigned ncdirect_palette_size(const ncdirect* nc){ return nc->tcache.colors; } diff --git a/src/lib/internal.h b/src/lib/internal.h index 821104dde..1f142663c 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -205,7 +205,7 @@ typedef struct ncmenu { // terminfo cache typedef struct tinfo { - int colors; // number of colors terminfo reported usable for this screen + unsigned colors;// number of colors terminfo reported usable for this screen char* sgr; // set many graphics properties at once char* sgr0; // restore default presentation properties char* setaf; // set foreground color (ANSI) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 0f5def1f9..8c60ec345 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1539,7 +1539,7 @@ unsigned notcurses_supported_styles(const notcurses* nc){ return styles; } -int notcurses_palette_size(const notcurses* nc){ +unsigned notcurses_palette_size(const notcurses* nc){ return nc->tcache.colors; } diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index bbf1faf2e..cc4be6b1a 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -46,12 +46,14 @@ int terminfostr(char** gseq, const char* name){ int interrogate_terminfo(tinfo* ti){ memset(ti, 0, sizeof(*ti)); ti->RGBflag = query_rgb(); - if((ti->colors = tigetnum("colors")) <= 0){ + int colors = tigetnum("colors"); + if(colors <= 0){ ti->colors = 1; ti->CCCflag = false; ti->RGBflag = false; ti->initc = NULL; }else{ + ti->colors = colors; terminfostr(&ti->initc, "initc"); if(ti->initc){ ti->CCCflag = tigetflag("ccc") == 1;