From f9eed1c4121f7642556576ac124139570a2ed650 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 00:27:27 -0400 Subject: [PATCH 1/3] 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; From d884dea8d72dc6acfe9811cec9e967b437aed4bd Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 01:22:53 -0400 Subject: [PATCH 2/3] notcurses-capabilities man page --- doc/man/index.html | 1 + doc/man/man3/notcurses.3.md | 1 + doc/man/man3/notcurses_capabilities.3.md | 80 ++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 doc/man/man3/notcurses_capabilities.3.md diff --git a/doc/man/index.html b/doc/man/index.html index dd3bcb860..476ae39df 100644 --- a/doc/man/index.html +++ b/doc/man/index.html @@ -41,6 +41,7 @@ Packaging status + notcurses_cell—runtime capability detection
notcurses_cell—operations on cell objects
notcurses_channels—operations on the channel type
notcurses_directmode—minimal notcurses instances for styling text
diff --git a/doc/man/man3/notcurses.3.md b/doc/man/man3/notcurses.3.md index 90f9ef21f..667942f4b 100644 --- a/doc/man/man3/notcurses.3.md +++ b/doc/man/man3/notcurses.3.md @@ -137,6 +137,7 @@ previous action. **ncurses(3NCURSES)**, **notcurses-demo(1)**, **notcurses-input(1)**, +**notcurses_capabilities(3)**, **notcurses_cell(3)**, **notcurses_channels(3)**, **notcurses_directmode(3)**, diff --git a/doc/man/man3/notcurses_capabilities.3.md b/doc/man/man3/notcurses_capabilities.3.md new file mode 100644 index 000000000..fa0fa69fd --- /dev/null +++ b/doc/man/man3/notcurses_capabilities.3.md @@ -0,0 +1,80 @@ +% notcurses_capabilities(3) +% nick black +% v1.6.12 + +# NAME + +notcurses_capabilities - runtime capability detection + +# SYNOPSIS + +**#include ** + +**unsigned notcurses_supported_styles(const struct notcurses* nc);** + +**unsigned notcurses_palette_size(const struct notcurses* nc);** + +**bool notcurses_cantruecolor(const struct notcurses* nc);** + +**bool notcurses_canfade(const struct notcurses* nc);** + +**bool notcurses_canchangecolor(const struct notcurses* nc);** + +**bool notcurses_canopen_images(const struct notcurses* nc);** + +**bool notcurses_canopen_videos(const struct notcurses* nc);** + +**bool notcurses_canutf8(const struct notcurses* nc);** + +**bool notcurses_cansixel(const struct notcurses* nc);** + +# DESCRIPTION + +**notcurses_supported_styles** returns a bitmask representing those styles +for which the terminal advertises support. + +**notcurses_palette_size** returns the size of the terminal's palette, used +for palette-indexed color. It will always return at least 1. This is +independent of RGB TrueColor support. No terminal is know to support +more than 256-indexed color. + +**notcurses_cantruecolor** returns **true** if the terminal advertises +support for RGB TrueColor. Note that the RGB APIs of Notcurses can be used +even in the absence of terminal RGB support (Notcurses will map the RGB +values to the palette). + +**notcurses_canfade** returns **true** if Notcurses has a means by which +it can effect fades. + +**notcurses_canchangecolor** returns **true** if the terminal advertises +support for changing its palette entries. + +**notcurses_canopen_images** returns **true** if Notcurses was built with +multimedia support. + +**notcurses_canopen_video** returns **true** if Notcurses was built with +multimedia support capable of decoding videos. + +**notcurses_canutf8** returns **true** if the configured locale uses +UTF-8 encoding. + +**notcurses_cansixel** returns **true** if the terminal advertises +support for Sixel, and Notcurses has been built with Sixel support. + +# BUGS + +Notcurses does not yet have Sixel support, and thus **notcurses_cansixel** +will always return **false**. + +# NOTES + +Some terminals advertise support for TrueColor, but then downsample or +otherwise degrade the provided RGB. In this case **notcurses_cantruecolor** +will return **true**, but the full spectrum will not be available. + +# RETURN VALUES + +# SEE ALSO + +**notcurses(3)**, +utf8(7) From 50ba30b11335021b6c3f682a26f0a36b92411e75 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 01:23:39 -0400 Subject: [PATCH 3/3] NEWS: mention notcurses_palette_size() --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 9c5287c37..6c62309cb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ rearrangements of Notcurses. for you save less memory consumption per plane, and faster operation. In the course of doing so, the `attrword` field of the `cell` structure was renamed `stylemask`, and reduced from 32 to 16 bits. + * `notcurses_palette_size()` now returns `unsigned`. * 1.6.12 (2020-08-12) * `ncreel`s `tabletcb` callback function semantics are radically simplified.