diff --git a/doc/man/man3/notcurses_multiselector.3.md b/doc/man/man3/notcurses_multiselector.3.md index 20d9d8c36..8b8e8fd61 100644 --- a/doc/man/man3/notcurses_multiselector.3.md +++ b/doc/man/man3/notcurses_multiselector.3.md @@ -16,9 +16,8 @@ struct notcurses; struct ncmultiselector; struct ncmselector_item { - char* option; - char* desc; - bool selected; + const char* option; + const char* desc; }; typedef struct ncmultiselector_options { diff --git a/doc/man/man3/notcurses_selector.3.md b/doc/man/man3/notcurses_selector.3.md index e709a7c96..e576c1c53 100644 --- a/doc/man/man3/notcurses_selector.3.md +++ b/doc/man/man3/notcurses_selector.3.md @@ -16,8 +16,8 @@ struct notcurses; struct ncselector; struct ncselector_item { - char* option; - char* desc; + const char* option; + const char* desc; }; typedef struct ncselector_options { diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index c8f9b075a..620b72432 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -3325,10 +3325,8 @@ API void ncplane_greyscale(struct ncplane* n); // // At all times, exactly one item is selected. struct ncselector_item { - char* option; - char* desc; - size_t opcolumns; // filled in by library - size_t desccolumns; // filled in by library + const char* option; + const char* desc; }; typedef struct ncselector_options { @@ -3384,8 +3382,8 @@ API bool ncselector_offer_input(struct ncselector* n, const ncinput* nc) API void ncselector_destroy(struct ncselector* n, char** item); struct ncmselector_item { - char* option; - char* desc; + const char* option; + const char* desc; bool selected; }; diff --git a/src/demo/zoo.c b/src/demo/zoo.c index 4e3d21d91..f75fa6e47 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -27,7 +27,7 @@ draw_background(struct notcurses* nc){ // we list all distributions on which notcurses is known to exist static struct ncselector_item select_items[] = { -#define SITEM(short, long) { short, long, 0, 0, } +#define SITEM(s, l) { s, l, } SITEM("fbsd", "FreeBSD"), SITEM("deb", "Debian Unstable Linux"), SITEM("rpm", "Fedora Rawhide Linux"), diff --git a/src/lib/selector.c b/src/lib/selector.c index 97132a0cc..d3992f894 100644 --- a/src/lib/selector.c +++ b/src/lib/selector.c @@ -1,5 +1,19 @@ #include "internal.h" +// internal ncselector item +struct ncselector_int { + char* option; + char* desc; + size_t opcolumns; // filled in by library + size_t desccolumns; // filled in by library +}; + +struct ncmselector_int { + char* option; + char* desc; + bool selected; +}; + typedef struct ncselector { ncplane* ncp; // backing ncplane unsigned selected; // index of selection @@ -7,7 +21,7 @@ typedef struct ncselector { unsigned maxdisplay; // max number of items to display, 0 -> no limit int longop; // columns occupied by longest option int longdesc; // columns occupied by longest description - struct ncselector_item* items; // list of items and descriptions, heap-copied + struct ncselector_int* items; // list of items and descriptions, heap-copied unsigned itemcount; // number of pairs in 'items' char* title; // can be NULL, in which case there's no riser int titlecols; // columns occupied by title @@ -29,7 +43,7 @@ typedef struct ncmultiselector { unsigned startdisp; // index of first option displayed unsigned maxdisplay; // max number of items to display, 0 -> no limit int longitem; // columns occupied by longest item - struct ncmselector_item* items; // items, descriptions, and statuses, heap-copied + struct ncmselector_int* items; // items, descriptions, and statuses, heap-copied unsigned itemcount; // number of pairs in 'items' char* title; // can be NULL, in which case there's no riser int titlecols; // columns occupied by title @@ -332,7 +346,7 @@ int ncselector_additem(ncselector* n, const struct ncselector_item* item){ int origdimy, origdimx; ncselector_dim_yx(n, &origdimy, &origdimx); size_t newsize = sizeof(*n->items) * (n->itemcount + 1); - struct ncselector_item* items = realloc(n->items, newsize); + struct ncselector_int* items = realloc(n->items, newsize); if(!items){ return -1; } diff --git a/src/poc/selector.c b/src/poc/selector.c index 1a8d1b0d1..1e55bbd2c 100644 --- a/src/poc/selector.c +++ b/src/poc/selector.c @@ -6,7 +6,7 @@ #include "version.h" static struct ncselector_item items[] = { -#define SITEM(short, long) { short, long, 0, 0, } +#define SITEM(s, l) { s, l, } SITEM("Afrikaans", "Ek kan glas eet, dit maak my nie seer nie."), SITEM("AngloSax", "ᛁᚳ᛫ᛗᚨᚷ᛫ᚷᛚᚨᛋ᛫ᛖᚩᛏᚪᚾ᛫ᚩᚾᛞ᛫ᚻᛁᛏ᛫ᚾᛖ᛫ᚻᛖᚪᚱᛗᛁᚪᚧ᛫ᛗᛖ᛬"), SITEM("Japanese", "私はガラスを食べられます。それは私を傷つけません。"), diff --git a/src/tests/selector.cpp b/src/tests/selector.cpp index 5957317ec..02cc4c285 100644 --- a/src/tests/selector.cpp +++ b/src/tests/selector.cpp @@ -109,10 +109,10 @@ TEST_CASE("Selectors") { SUBCASE("PopulatedSelector") { ncselector_item items[] = { - { strdup("op1"), strdup("this is option 1"), 0, 0, }, - { strdup("2ndop"), strdup("this is option #2"), 0, 0, }, - { strdup("tres"), strdup("option the third"), 0, 0, }, - { NULL, NULL, 0, 0, }, + { strdup("op1"), strdup("this is option 1"), }, + { strdup("2ndop"), strdup("this is option #2"), }, + { strdup("tres"), strdup("option the third"), }, + { NULL, NULL, }, }; struct ncselector_options opts{}; opts.items = items; @@ -164,10 +164,10 @@ TEST_CASE("Selectors") { SUBCASE("SelectorMovement") { ncselector_item items[] = { - { strdup("op1"), strdup("this is option 1"), 0, 0, }, - { strdup("2ndop"), strdup("this is option #2"), 0, 0, }, - { strdup("tres"), strdup("option the third"), 0, 0, }, - { NULL, NULL, 0, 0, }, + { strdup("op1"), strdup("this is option 1"), }, + { strdup("2ndop"), strdup("this is option #2"), }, + { strdup("tres"), strdup("option the third"), }, + { NULL, NULL, }, }; struct ncselector_options opts{}; opts.items = items; @@ -210,10 +210,10 @@ TEST_CASE("Selectors") { // Provide three items, limited to 1 shown at a time SUBCASE("ScrollingSelectorOne") { ncselector_item items[] = { - { strdup("op1"), strdup("this is option 1"), 0, 0, }, - { strdup("2ndop"), strdup("this is option #2"), 0, 0, }, - { strdup("tres"), strdup("option the third"), 0, 0, }, - { NULL, NULL, 0, 0, }, + { strdup("op1"), strdup("this is option 1"), }, + { strdup("2ndop"), strdup("this is option #2"), }, + { strdup("tres"), strdup("option the third"), }, + { NULL, NULL, }, }; struct ncselector_options opts{}; opts.maxdisplay = 1; @@ -262,10 +262,10 @@ TEST_CASE("Selectors") { // Provide three items, limited to 2 shown at a time SUBCASE("ScrollingSelectorTwo") { ncselector_item items[] = { - { strdup("op1"), strdup("this is option 1"), 0, 0, }, - { strdup("2ndop"), strdup("this is option #2"), 0, 0, }, - { strdup("tres"), strdup("option the third"), 0, 0, }, - { NULL, NULL, 0, 0, }, + { strdup("op1"), strdup("this is option 1"), }, + { strdup("2ndop"), strdup("this is option #2"), }, + { strdup("tres"), strdup("option the third"), }, + { NULL, NULL, }, }; struct ncselector_options opts{}; opts.maxdisplay = 2;