From 42f26fcb1eaeb7fe664d3368d90c9f4d3fa3c5a2 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 18 May 2021 03:28:50 -0400 Subject: [PATCH] ncls: update to prep_image() maxy/maxx #1661 --- NEWS.md | 5 +++++ USAGE.md | 2 +- doc/man/man3/notcurses_direct.3.md | 4 ++++ src/ls/main.cpp | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 068218ac6..9dca87eed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,11 @@ rearrangements of Notcurses. * Fixed bad bug in `ncvisual_resize()` when growing an image. This isn't relevant to enlarging an `ncvisual` via scaling, but only when persistently growing one with `ncvisual_resize()`. + * Direct mode image rendering now honors the `maxy` and `maxx` parameters, + which specify the maximum number of cell rows and columns, respectively, + to use for the render. They were previously ignored, contrary to + documentation. It is now an error to pass a negative number for either of + these values. Use 0 to specify "as much space as is necessary". * Added `ncdirectf_from_file()`, `ncdirectf_geom()`, and `ncdirectf_render()`, with the net result that you can now (efficiently) get media geometry in direct mode. If you don't care about media geometry, you can keep using diff --git a/USAGE.md b/USAGE.md index d1b5422bc..a1cb26eb9 100644 --- a/USAGE.md +++ b/USAGE.md @@ -467,7 +467,7 @@ int ncdirect_render_image(struct ncdirect* nc, const char* filename, // -- but will only occupy the column of the cursor, and those to the right. // To actually write (and free) this, invoke ncdirect_raster_frame(). 'maxx' // and 'maxy', if greater than 0, are used for scaling; the terminal's geometry -// is otherwise used. +// is otherwise used. It is an error to pass a negative 'maxy' or 'maxx'. ncdirectv* ncdirect_render_frame(struct ncdirect* n, const char* filename, ncblitter_e blitter, ncscale_e scale, int maxy, int maxx); diff --git a/doc/man/man3/notcurses_direct.3.md b/doc/man/man3/notcurses_direct.3.md index 0eda4bb81..8bf700931 100644 --- a/doc/man/man3/notcurses_direct.3.md +++ b/doc/man/man3/notcurses_direct.3.md @@ -179,6 +179,10 @@ must be supplied to **ncdirect_init**. before **NCBLIT_PIXEL** can be used to render images; see **notcurses_visual(3)** for more details. +When rendering an image, ***maxy*** and ***maxx*** specify a maximum number +of (cell) rows and columns to use, respectively. Passing 0 means "use as much +space as is necessary". It is an error to pass a negative number for either. + # RETURN VALUES **ncdirect_init** returns **NULL** on failure. Otherwise, the return value diff --git a/src/ls/main.cpp b/src/ls/main.cpp index bc2fef8c4..9c457e140 100644 --- a/src/ls/main.cpp +++ b/src/ls/main.cpp @@ -147,7 +147,7 @@ void ncls_thread(const lsContext* ctx) { work.pop(); pthread_mutex_unlock(&mtx); auto s = j.dir / j.p; - auto faken = ctx->nc.prep_image(s.c_str(), ctx->blitter, ctx->scaling, -1, -1); + auto faken = ctx->nc.prep_image(s.c_str(), ctx->blitter, ctx->scaling, 0, 0); pthread_mutex_lock(&outmtx); std::cout << j.p << '\n'; if(faken){