[multiselector] refuse a bound plane #2347

This commit is contained in:
nick black 2021-11-17 00:35:28 -05:00
parent 717b4a40c1
commit ce2a6dc686
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 14 additions and 1 deletions

View File

@ -882,6 +882,10 @@ ncmultiselector_dim_yx(const ncmultiselector* n, unsigned* ncdimy, unsigned* ncd
}
ncmultiselector* ncmultiselector_create(ncplane* n, const ncmultiselector_options* opts){
if(n == notcurses_stdplane(ncplane_notcurses(n))){
logerror("won't use the standard plane\n"); // would fail later on resize
return NULL;
}
ncmultiselector_options zeroed = {};
if(!opts){
opts = &zeroed;
@ -959,8 +963,10 @@ ncmultiselector* ncmultiselector_create(ncplane* n, const ncmultiselector_option
if(ncplane_resize_simple(ns->ncp, dimy, dimx)){
goto freeitems;
}
if(ncplane_set_widget(ns->ncp, ns, (void(*)(void*))ncmultiselector_destroy)){
goto freeitems;
}
ncmultiselector_draw(ns); // deal with error here?
ncplane_set_widget(ns->ncp, ns, (void(*)(void*))ncmultiselector_destroy);
return ns;
freeitems:

View File

@ -11,6 +11,13 @@ TEST_CASE("Selectors") {
REQUIRE(n_);
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
// selector can't be bound to the standard plane
SUBCASE("RefuseStandardPlane") {
ncselector_options s{};
struct ncselector* ns = ncselector_create(n_, &s);
REQUIRE(nullptr == ns);
}
// create a selector, but don't explicitly destroy it, thus testing the
// context shutdown cleanup path
SUBCASE("ImplicitDestroy") {