From 6b126f4049b9821f42418a8f3ae1c34b2d6aa453 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 7 Feb 2021 18:31:31 -0500 Subject: [PATCH] add notcurses_canbraille() capability test --- NEWS.md | 3 +++ USAGE.md | 6 ++++++ doc/man/man3/notcurses_capabilities.3.md | 5 ++++- include/notcurses/notcurses.h | 3 +++ src/lib/notcurses.c | 4 ++++ tests/plot.cpp | 6 ++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index ec528a946..6ae751d1b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ This document attempts to list user-visible changes and any major internal rearrangements of Notcurses. +* 2.1.9 (not yet released) + * Add `notcurses_canbraille()` capability predicate. + * 2.1.8 (2021-02-03): * The `notcurses-tetris` binary has been renamed `nctetris`. * The new function `channel_set_palindex()` has been added. diff --git a/USAGE.md b/USAGE.md index 799f7e3cd..ca91870a3 100644 --- a/USAGE.md +++ b/USAGE.md @@ -300,6 +300,12 @@ bool notcurses_canutf8(const struct notcurses* nc); // Can we blit to Sixel? This requires being built against libsixel. bool notcurses_cansixel(const struct notcurses* nc); + +// Can we draw sextants? This requires Unicode 13. +bool notcurses_cansextants(const struct notcurses* nc); + +// Can we draw Braille? The Linux console cannot. +bool notcurses_canbraille(const struct notcurses* nc); ``` ## Direct mode diff --git a/doc/man/man3/notcurses_capabilities.3.md b/doc/man/man3/notcurses_capabilities.3.md index 2208fca37..38d52b7fe 100644 --- a/doc/man/man3/notcurses_capabilities.3.md +++ b/doc/man/man3/notcurses_capabilities.3.md @@ -28,6 +28,8 @@ notcurses_capabilities - runtime capability detection **bool notcurses_cansextant(const struct notcurses* ***nc***);** +**bool notcurses_canbraille(const struct notcurses* ***nc***);** + **bool notcurses_cansixel(const struct notcurses* ***nc***);** # DESCRIPTION @@ -64,7 +66,8 @@ UTF-8 encoding, and the locale was successfully loaded. that the terminal can properly render Unicode 13 sextants. **notcurses_cansixel** returns **true** if the terminal advertises -support for Sixel. +support for Sixel. **notcurses_canbraille** returns **true** if Braille +is expected to work on the terminal. # BUGS diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 135262fcb..2e0cb985b 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1228,6 +1228,9 @@ API bool notcurses_canutf8(const struct notcurses* nc); // Can we reliably use Unicode 13 sextants? API bool notcurses_cansextant(const struct notcurses* nc); +// Can we reliably use Unicode Braille? +API bool notcurses_canbraille(const struct notcurses* nc); + // Can we blit to Sixel? API bool notcurses_cansixel(const struct notcurses* nc); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 49152e73e..627b48ecc 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2053,6 +2053,10 @@ bool notcurses_cansextant(const notcurses* nc){ return nc->tcache.sextants && nc->tcache.utf8; } +bool notcurses_canbraille(const notcurses* nc){ + return nc->tcache.braille && nc->tcache.utf8; +} + bool notcurses_canfade(const notcurses* nc){ return nc->tcache.CCCflag || nc->tcache.RGBflag; } diff --git a/tests/plot.cpp b/tests/plot.cpp index 007152d0f..ed5a519fb 100644 --- a/tests/plot.cpp +++ b/tests/plot.cpp @@ -146,6 +146,9 @@ TEST_CASE("Plot") { } SUBCASE("BraillePlot") { + if(!notcurses_canbraille(nc_)){ + return; + } ncplane_options nopts = { .y = 1, .x = 1, .rows = 6, .cols = 50, .userptr = nullptr, .name = "plot", .resizecb = nullptr, .flags = 0, @@ -250,6 +253,9 @@ TEST_CASE("Plot") { } SUBCASE("BraillePlot1Row") { + if(!notcurses_canbraille(nc_)){ + return; + } ncplane_options nopts = { .y = 1, .x = 1, .rows = 1, .cols = 25, .userptr = nullptr, .name = "plot", .resizecb = nullptr, .flags = 0,