From 96c6dc8e16d68aa7c933fb3a03756bb64e0c4dfa Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 10 Jul 2020 17:13:46 -0400 Subject: [PATCH] add ncdirect_canopen_images() and ncdirect_canutf8() #753 --- USAGE.md | 7 +++++++ doc/man/man3/notcurses_directmode.3.md | 4 ++++ include/notcurses/direct.h | 10 ++++++++-- python/src/notcurses/build_notcurses.py | 2 ++ src/lib/direct.cpp | 18 ++++++++++++++++++ src/poc/vizdirect.c | 4 ++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 1ac74665f..4d79ac342 100644 --- a/USAGE.md +++ b/USAGE.md @@ -364,6 +364,13 @@ nc_err_e ncdirect_render_image(struct ncdirect* nc, const char* filename, ncblitter_e blitter, ncscale_e scale); ``` +Several of the Notcurses capability predicates have `ncdirect` analogues: + +```c +bool ncdirect_canopen_images(const struct ncdirect* n); +bool ncdirect_canutf8(const struct ncdirect* n); +``` + ## Alignment Most functions that generate output can be aligned relative to an ncplane. diff --git a/doc/man/man3/notcurses_directmode.3.md b/doc/man/man3/notcurses_directmode.3.md index f8c82bee3..7668f783c 100644 --- a/doc/man/man3/notcurses_directmode.3.md +++ b/doc/man/man3/notcurses_directmode.3.md @@ -56,6 +56,10 @@ ncdirect_init - minimal notcurses instances for styling text **int ncdirect_putstr(struct ncdirect* nc, uint64_t channels, const char* utf8);** +**bool ncdirect_canopen_images(const struct ncdirect* n);** + +**bool ncdirect_canutf8(const struct ncdirect* n);** + **nc_err_e ncdirect_render_image(struct ncdirect* n, const char* filename, ncblitter_e blitter, ncscale_e scale);** # DESCRIPTION diff --git a/include/notcurses/direct.h b/include/notcurses/direct.h index 334d1a71c..ff615cf28 100644 --- a/include/notcurses/direct.h +++ b/include/notcurses/direct.h @@ -96,8 +96,11 @@ API nc_err_e ncdirect_render_image(struct ncdirect* n, const char* filename, // Clear the screen. API int ncdirect_clear(struct ncdirect* nc); -// Release 'nc' and any associated resources. 0 on success, non-0 on failure. -API int ncdirect_stop(struct ncdirect* nc); +// Can we load images? This requires being built against FFmpeg/OIIO. +API bool ncdirect_canopen_images(const struct ncdirect* n); + +// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. +API bool ncdirect_canutf8(const struct ncdirect* n); // Draw horizontal/vertical lines using the specified channels, interpolating // between them as we go. The EGC may not use more than one column. For a @@ -109,6 +112,9 @@ API int ncdirect_hline_interp(struct ncdirect* n, const char* egc, int len, API int ncdirect_vline_interp(struct ncdirect* n, const char* egc, int len, uint64_t h1, uint64_t h2); +// Release 'nc' and any associated resources. 0 on success, non-0 on failure. +API int ncdirect_stop(struct ncdirect* nc); + #undef API #ifdef __cplusplus diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index 923d4b2a4..00b95c151 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -503,6 +503,8 @@ int ncdirect_cursor_right(struct ncdirect* nc, int num); int ncdirect_cursor_down(struct ncdirect* nc, int num); int ncdirect_hline_interp(struct ncdirect* n, const char* egc, int len, uint64_t h1, uint64_t h2); int ncdirect_vline_interp(struct ncdirect* n, const char* egc, int len, uint64_t h1, uint64_t h2); +bool ncdirect_canopen_images(const struct ncdirect* n); +bool ncdirect_canutf8(const struct ncdirect* n); nc_err_e ncdirect_render_image(struct ncdirect* n, const char* filename, ncalign_e align, ncblitter_e blitter, ncscale_e scale); """) diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index acb1b573e..ef55976e4 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -651,3 +651,21 @@ int ncdirect_vline_interp(ncdirect* n, const char* egc, int len, } return ret; } + +// Can we load images? This requires being built against FFmpeg/OIIO. +bool ncdirect_canopen_images(const ncdirect* n){ + (void)n; +#ifdef USE_FFMPEG + return true; +#else +#ifdef USE_OIIO + return true; +#endif +#endif + return false; +} + +// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. +bool ncdirect_canutf8(const ncdirect* n){ + return n->utf8; +} diff --git a/src/poc/vizdirect.c b/src/poc/vizdirect.c index 18d92b9a3..4d6c38975 100644 --- a/src/poc/vizdirect.c +++ b/src/poc/vizdirect.c @@ -12,6 +12,10 @@ int main(void){ if((n = ncdirect_init(NULL, stdout)) == NULL){ return EXIT_FAILURE; } + if(!ncdirect_canopen_images(n)){ + fprintf(stderr, "This notcurses was not build with multimedia support.\n"); + return EXIT_FAILURE; + } if(ncdirect_render_image(n, "../data/normal.png", NCALIGN_LEFT, NCBLIT_DEFAULT, NCSCALE_STRETCH) != NCERR_SUCCESS){ return EXIT_FAILURE;