ncreader_create: accept const options #403

pull/592/head
nick black 4 years ago committed by Nick Black
parent 7683973ee4
commit d174431187

@ -2756,7 +2756,7 @@ API int ncsubproc_destroy(struct ncsubproc* n);
// is (version * 4 + 17) columns wide, and ⌈version * 4 + 17 / 2⌉ rows tall. If
// maxversion is not zero, it plays a hard limit on the QR code size. Though the
// max version of current QR codes is 40, greater values are allowed, for
// future compatability (provide 0 for no artificail bound).
// future compatability (provide 0 for no artificial bound).
API int ncplane_qrcode(struct ncplane* n, int maxversion, const void* data, size_t len);
// Promote an ncplane 'n' to an ncvisual. The plane should not be associated
@ -2782,7 +2782,7 @@ typedef struct ncreader_options {
// supporting readline keybindings. 'rows' and 'cols' both must be negative.
// there are no restrictions on 'y' or 'x'. creates its own plane.
API struct ncreader* ncreader_create(struct notcurses* nc, int y, int x,
ncreader_options* opts);
const ncreader_options* opts);
// empty the ncreader of any user input, and home the cursor.
API int ncreader_clear(struct ncreader* n);

@ -1,9 +1,12 @@
#include "internal.h"
ncreader* ncreader_create(notcurses* nc, int y, int x, ncreader_options* opts){
ncreader* ncreader_create(notcurses* nc, int y, int x, const ncreader_options* opts){
if(opts->physrows <= 0 || opts->physcols <= 0){
return NULL;
}
if(opts->egc == NULL){
return NULL;
}
ncreader* nr = malloc(sizeof(*nr));
if(nr){
nr->ncp = ncplane_new(nc, opts->physrows, opts->physcols, y, x, NULL);
@ -11,6 +14,10 @@ ncreader* ncreader_create(notcurses* nc, int y, int x, ncreader_options* opts){
free(nr);
return NULL;
}
if(ncplane_set_base(nr->ncp, opts->egc, opts->eattrword, opts->echannels) <= 0){
ncreader_destroy(nr);
return NULL;
}
// FIXME
}
return nr;

@ -31,12 +31,16 @@ TEST_CASE("Readers") {
CHECK(!nr);
}
SUBCASE("ReaderLifecycle") {
SUBCASE("ReaderRender") {
ncreader_options opts{};
opts.physrows = 1;
opts.physcols = dimx / 2;
opts.egc = strdup("");
auto nr = ncreader_create(nc_, 0, 0, &opts);
REQUIRE(nullptr != nr);
CHECK(0 == notcurses_render(nc_));
CHECK(0 < ncplane_set_base(n_, opts.egc, opts.eattrword, opts.echannels));
sleep(5);
ncreader_destroy(nr);
CHECK(0 == notcurses_render(nc_));
}

Loading…
Cancel
Save