From 104bbfef503ff4648c17e2c4019626b3b16abdc9 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 19 Jul 2020 21:53:01 -0400 Subject: [PATCH] add notcurses_lex_blitter() --- NEWS.md | 5 +++++ USAGE.md | 9 +++++++++ doc/man/man3/notcurses_visual.3.md | 6 ++++++ include/notcurses/notcurses.h | 6 ++++++ python/src/notcurses/build_notcurses.py | 3 +++ src/lib/blit.c | 16 ++++++++++++++++ 6 files changed, 45 insertions(+) diff --git a/NEWS.md b/NEWS.md index 9ca5e3890..09099611e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ This document attempts to list user-visible changes and any major internal rearrangements of Notcurses. +* 1.6.6 (2020-07-19) + * `notcurses-pydemo` is now only installed alongside the Python module, + using setuptools. CMake no longer installs it. + * Added `notcurses_lex_blitter()` and `notcurses_str_scalemode()`. + * 1.6.5 (2020-07-19) * No user-visible changes. diff --git a/USAGE.md b/USAGE.md index 51f0f2ca5..b3718d7bb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -2639,6 +2639,9 @@ typedef enum { NCBLIT_SIXEL, // 6 rows, 1 col (RGB), spotty support among terminals } ncblitter_e; +// Lex a blitter. +int notcurses_lex_blitter(const char* op, ncblitter_e* blitter); + // Get the name of a blitter. const char* notcurses_str_blitter(ncblitter_e blitter); @@ -2671,6 +2674,12 @@ typedef enum { NCSCALE_STRETCH, } ncscale_e; +// Lex a visual scaling mode (one of "none", "stretch", or "scale"). +int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode); + +// Get the name of a scaling mode. +const char* notcurses_str_scalemode(ncscale_e scalemode); + // the streaming operation ceases immediately, and that value is propagated out. // The recommended absolute display time target is passed in 'tspec'. typedef int (*streamcb)(struct ncplane*, struct ncvisual*, diff --git a/doc/man/man3/notcurses_visual.3.md b/doc/man/man3/notcurses_visual.3.md index e8bdd55c3..174b8d1eb 100644 --- a/doc/man/man3/notcurses_visual.3.md +++ b/doc/man/man3/notcurses_visual.3.md @@ -82,6 +82,12 @@ typedef int (*streamcb)(struct notcurses*, struct ncvisual*, void*); **char* ncvisual_subtitle(const struct ncvisual* ncv);** +**int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode);** + +**const char* notcurses_str_scalemode(ncscale_e scalemode);** + +**int notcurses_lex_blitter(const char* op, ncblitter_e* blitter);** + **const char* notcurses_str_blitter(ncblitter_e blitter);** # DESCRIPTION diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 80d39a526..a48582b1a 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -895,12 +895,18 @@ typedef struct notcurses_options { // there can be four numbers separated by commas. API int notcurses_lex_margins(const char* op, notcurses_options* opts); +// Lex a blitter. +API int notcurses_lex_blitter(const char* op, ncblitter_e* blitter); + // Get the name of a blitter. API const char* notcurses_str_blitter(ncblitter_e blitter); // Lex a visual scaling mode (one of "none", "stretch", or "scale"). API int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode); +// Get the name of a scaling mode. +API const char* notcurses_str_scalemode(ncscale_e scalemode); + // Initialize a notcurses context on the connected terminal at 'fp'. 'fp' must // be a tty. You'll usually want stdout. NULL can be supplied for 'fp', in // which case /dev/tty will be opened. Returns NULL on error, including any diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index 703407c39..875d76c2d 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -146,6 +146,7 @@ typedef enum { NCBLIT_SIXEL, // 6 rows, 1 col (RGB) } ncblitter_e; const char* notcurses_str_blitter(ncblitter_e blitter); +int notcurses_lex_blitter(const char* op, ncblitter_e* blitter); uint32_t* ncplane_rgba(const struct ncplane* nc, ncblitter_e blit, int begy, int begx, int leny, int lenx); char* ncplane_contents(const struct ncplane* nc, int begy, int begx, int leny, int lenx); void* ncplane_set_userptr(struct ncplane* n, void* opaque); @@ -273,6 +274,8 @@ typedef enum { NCSCALE_SCALE, NCSCALE_STRETCH, } ncscale_e; +int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode); +const char* notcurses_str_scalemode(ncscale_e scalemode); struct ncvisual* ncvisual_from_file(const char* file, nc_err_e* ncerr); struct ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols); struct ncvisual* ncvisual_from_bgra(const void* rgba, int rows, int rowstride, int cols); diff --git a/src/lib/blit.c b/src/lib/blit.c index f88f1cfb3..372b85878 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -499,6 +499,22 @@ const struct blitset notcurses_blitters[] = { .blit = NULL, .name = NULL, .fill = false, }, }; +int notcurses_lex_blitter(const char* op, ncblitter_e* blitter){ + const struct blitset* bset = notcurses_blitters; + while(bset->name){ + if(strcasecmp(bset->name, op) == 0){ + *blitter = bset->geom; + return 0; + } + ++bset; + } + if(strcasecmp("default", op) == 0){ + *blitter = NCBLIT_DEFAULT; + return 0; + } + return -1; +} + const char* notcurses_str_blitter(ncblitter_e blitter){ if(blitter == NCBLIT_DEFAULT){ return "default";