all widgets check flags and warn on undefined #627

pull/1008/head
nick black 4 years ago
parent ec077a0bf2
commit 3f726edd4c
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1167,23 +1167,23 @@ ncplane_resize_simple(struct ncplane* n, int ylen, int xlen){
// Destroy the specified ncplane. None of its contents will be visible after // Destroy the specified ncplane. None of its contents will be visible after
// the next call to notcurses_render(). It is an error to attempt to destroy // the next call to notcurses_render(). It is an error to attempt to destroy
// the standard plane. // the standard plane.
API int ncplane_destroy(struct ncplane* ncp); API int ncplane_destroy(struct ncplane* n);
// Set the ncplane's base cell to this cell. It will be used for purposes of // Set the ncplane's base cell to this cell. It will be used for purposes of
// rendering anywhere that the ncplane's gcluster is 0. Erasing the ncplane // rendering anywhere that the ncplane's gcluster is 0. Erasing the ncplane
// does not reset the base cell; this function must be called with a zero 'c'. // does not reset the base cell; this function must be called with a zero 'c'.
API int ncplane_set_base_cell(struct ncplane* ncp, const cell* c); API int ncplane_set_base_cell(struct ncplane* n, const cell* c);
// Set the ncplane's base cell to this cell. It will be used for purposes of // Set the ncplane's base cell to this cell. It will be used for purposes of
// rendering anywhere that the ncplane's gcluster is 0. Erasing the ncplane // rendering anywhere that the ncplane's gcluster is 0. Erasing the ncplane
// does not reset the base cell; this function must be called with an empty // does not reset the base cell; this function must be called with an empty
// 'egc'. 'egc' must be a single extended grapheme cluster. // 'egc'. 'egc' must be a single extended grapheme cluster.
API int ncplane_set_base(struct ncplane* ncp, const char* egc, API int ncplane_set_base(struct ncplane* n, const char* egc,
uint32_t stylemask, uint64_t channels); uint32_t stylemask, uint64_t channels);
// Extract the ncplane's base cell into 'c'. The reference is invalidated if // Extract the ncplane's base cell into 'c'. The reference is invalidated if
// 'ncp' is destroyed. // 'ncp' is destroyed.
API int ncplane_base(struct ncplane* ncp, cell* c); API int ncplane_base(struct ncplane* n, cell* c);
// Move this plane relative to the standard plane, or the plane to which it is // Move this plane relative to the standard plane, or the plane to which it is
// bound (if it is bound to a plane). It is an error to attempt to move the // bound (if it is bound to a plane). It is an error to attempt to move the
@ -1271,10 +1271,10 @@ ncplane_at_yx_cell(struct ncplane* n, int y, int x, cell* c){
} }
// Create a flat string from the EGCs of the selected region of the ncplane // Create a flat string from the EGCs of the selected region of the ncplane
// 'nc'. Start at the plane's 'begy'x'begx' coordinate (which must lie on the // 'n'. Start at the plane's 'begy'x'begx' coordinate (which must lie on the
// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and // plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
// 'lenx' can be specified as -1 to go through the boundary of the plane. // 'lenx' can be specified as -1 to go through the boundary of the plane.
API char* ncplane_contents(const struct ncplane* nc, int begy, int begx, API char* ncplane_contents(const struct ncplane* n, int begy, int begx,
int leny, int lenx); int leny, int lenx);
// Manipulate the opaque user pointer associated with this plane. // Manipulate the opaque user pointer associated with this plane.
@ -1908,14 +1908,14 @@ cell_bg_palindex_p(const cell* cl){
// Extract the 32-bit working background channel from an ncplane. // Extract the 32-bit working background channel from an ncplane.
static inline unsigned static inline unsigned
ncplane_bchannel(const struct ncplane* nc){ ncplane_bchannel(const struct ncplane* n){
return channels_bchannel(ncplane_channels(nc)); return channels_bchannel(ncplane_channels(n));
} }
// Extract the 32-bit working foreground channel from an ncplane. // Extract the 32-bit working foreground channel from an ncplane.
static inline unsigned static inline unsigned
ncplane_fchannel(const struct ncplane* nc){ ncplane_fchannel(const struct ncplane* n){
return channels_fchannel(ncplane_channels(nc)); return channels_fchannel(ncplane_channels(n));
} }
API void ncplane_set_channels(struct ncplane* n, uint64_t channels); API void ncplane_set_channels(struct ncplane* n, uint64_t channels);
@ -1934,38 +1934,38 @@ API void ncplane_styles_off(struct ncplane* n, unsigned stylebits);
// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs. // Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
static inline unsigned static inline unsigned
ncplane_fg(const struct ncplane* nc){ ncplane_fg(const struct ncplane* n){
return channels_fg(ncplane_channels(nc)); return channels_fg(ncplane_channels(n));
} }
// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs. // Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
static inline unsigned static inline unsigned
ncplane_bg(const struct ncplane* nc){ ncplane_bg(const struct ncplane* n){
return channels_bg(ncplane_channels(nc)); return channels_bg(ncplane_channels(n));
} }
// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs. // Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
static inline unsigned static inline unsigned
ncplane_fg_alpha(const struct ncplane* nc){ ncplane_fg_alpha(const struct ncplane* n){
return channels_fg_alpha(ncplane_channels(nc)); return channels_fg_alpha(ncplane_channels(n));
} }
// Is the plane's foreground using the "default foreground color"? // Is the plane's foreground using the "default foreground color"?
static inline bool static inline bool
ncplane_fg_default_p(const struct ncplane* nc){ ncplane_fg_default_p(const struct ncplane* n){
return channels_fg_default_p(ncplane_channels(nc)); return channels_fg_default_p(ncplane_channels(n));
} }
// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs. // Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
static inline unsigned static inline unsigned
ncplane_bg_alpha(const struct ncplane* nc){ ncplane_bg_alpha(const struct ncplane* n){
return channels_bg_alpha(ncplane_channels(nc)); return channels_bg_alpha(ncplane_channels(n));
} }
// Is the plane's background using the "default background color"? // Is the plane's background using the "default background color"?
static inline bool static inline bool
ncplane_bg_default_p(const struct ncplane* nc){ ncplane_bg_default_p(const struct ncplane* n){
return channels_bg_default_p(ncplane_channels(nc)); return channels_bg_default_p(ncplane_channels(n));
} }
// Extract 24 bits of foreground RGB from 'n', split into components. // Extract 24 bits of foreground RGB from 'n', split into components.
@ -2017,7 +2017,7 @@ API int ncplane_set_bg_alpha(struct ncplane* n, int alpha);
// Called for each fade iteration on 'ncp'. If anything but 0 is returned, // Called for each fade iteration on 'ncp'. If anything but 0 is returned,
// the fading operation ceases immediately, and that value is propagated out. // the fading operation ceases immediately, and that value is propagated out.
// The recommended absolute display time target is passed in 'tspec'. // The recommended absolute display time target is passed in 'tspec'.
typedef int (*fadecb)(struct notcurses* nc, struct ncplane* ncp, typedef int (*fadecb)(struct notcurses* nc, struct ncplane* n,
const struct timespec*, void* curry); const struct timespec*, void* curry);
// Fade the ncplane out over the provided time, calling 'fader' at each // Fade the ncplane out over the provided time, calling 'fader' at each
@ -2256,7 +2256,7 @@ struct ncvisual_options {
// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and // plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
// 'lenx' can be specified as -1 to go through the boundary of the plane. // 'lenx' can be specified as -1 to go through the boundary of the plane.
// Only glyphs from the specified blitset may be present. // Only glyphs from the specified blitset may be present.
API uint32_t* ncplane_rgba(const struct ncplane* nc, ncblitter_e blit, API uint32_t* ncplane_rgba(const struct ncplane* n, ncblitter_e blit,
int begy, int begx, int leny, int lenx); int begy, int begx, int leny, int lenx);
// Get the size and ratio of ncvisual pixels to output cells along the y // Get the size and ratio of ncvisual pixels to output cells along the y
@ -2474,7 +2474,7 @@ struct ncreel;
// Take over the ncplane 'nc' and use it to draw a reel according to 'popts'. // Take over the ncplane 'nc' and use it to draw a reel according to 'popts'.
// The plane will be destroyed by ncreel_destroy(); this transfers ownership. // The plane will be destroyed by ncreel_destroy(); this transfers ownership.
API struct ncreel* ncreel_create(struct ncplane* nc, const ncreel_options* popts); API struct ncreel* ncreel_create(struct ncplane* n, const ncreel_options* popts);
// Returns the ncplane on which this ncreel lives. // Returns the ncplane on which this ncreel lives.
API struct ncplane* ncreel_plane(struct ncreel* pr); API struct ncplane* ncreel_plane(struct ncreel* pr);
@ -2826,7 +2826,7 @@ typedef struct ncmenu_options {
// Create a menu with the specified options. Menus are currently bound to an // Create a menu with the specified options. Menus are currently bound to an
// overall notcurses object (as opposed to a particular plane), and are // overall notcurses object (as opposed to a particular plane), and are
// implemented as ncplanes kept atop other ncplanes. // implemented as ncplanes kept atop other ncplanes.
API struct ncmenu* ncmenu_create(struct ncplane* nc, const ncmenu_options* opts); API struct ncmenu* ncmenu_create(struct ncplane* n, const ncmenu_options* opts);
// Unroll the specified menu section, making the menu visible if it was // Unroll the specified menu section, making the menu visible if it was
// invisible, and rolling up any menu section that is already unrolled. // invisible, and rolling up any menu section that is already unrolled.
@ -3038,7 +3038,7 @@ typedef struct ncreader_options {
// ncreaders provide freeform input in a (possibly multiline) region, // ncreaders provide freeform input in a (possibly multiline) region,
// supporting readline keybindings. 'rows' and 'cols' both must be negative. // supporting readline keybindings. 'rows' and 'cols' both must be negative.
// there are no restrictions on 'y' or 'x'. creates its own plane. // there are no restrictions on 'y' or 'x'. creates its own plane.
API struct ncreader* ncreader_create(struct ncplane* nc, int y, int x, API struct ncreader* ncreader_create(struct ncplane* n, int y, int x,
const ncreader_options* opts); const ncreader_options* opts);
// empty the ncreader of any user input, and home the cursor. // empty the ncreader of any user input, and home the cursor.
@ -3083,7 +3083,7 @@ struct blitset {
// quickly, i.e. it can be indexed as height arrays of 1 + height glyphs. i.e. // quickly, i.e. it can be indexed as height arrays of 1 + height glyphs. i.e.
// the first five braille EGCs are all 0 on the left, [0..4] on the right. // the first five braille EGCs are all 0 on the left, [0..4] on the right.
const wchar_t* egcs; const wchar_t* egcs;
int (*blit)(struct ncplane* nc, int placey, int placex, int linesize, int (*blit)(struct ncplane* n, int placey, int placex, int linesize,
const void* data, int begy, int begx, int leny, int lenx, const void* data, int begy, int begx, int leny, int lenx,
bool bgr, bool blendcolors); bool bgr, bool blendcolors);
const char* name; const char* name;

@ -100,6 +100,9 @@ static ncfdplane*
ncfdplane_create_internal(ncplane* n, const ncfdplane_options* opts, int fd, ncfdplane_create_internal(ncplane* n, const ncfdplane_options* opts, int fd,
ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn, ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn,
bool thread){ bool thread){
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
ncfdplane* ret = malloc(sizeof(*ret)); ncfdplane* ret = malloc(sizeof(*ret));
if(ret == NULL){ if(ret == NULL){
return ret; return ret;
@ -290,6 +293,9 @@ ncsubproc* ncsubproc_createv(ncplane* n, const ncsubproc_options* opts,
if(!cbfxn || !donecbfxn){ if(!cbfxn || !donecbfxn){
return NULL; return NULL;
} }
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
int fd = -1; int fd = -1;
ncsubproc* ret = malloc(sizeof(*ret)); ncsubproc* ret = malloc(sizeof(*ret));
if(ret == NULL){ if(ret == NULL){
@ -318,6 +324,9 @@ ncsubproc* ncsubproc_createvp(ncplane* n, const ncsubproc_options* opts,
if(!cbfxn || !donecbfxn){ if(!cbfxn || !donecbfxn){
return NULL; return NULL;
} }
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
int fd = -1; int fd = -1;
ncsubproc* ret = malloc(sizeof(*ret)); ncsubproc* ret = malloc(sizeof(*ret));
if(ret == NULL){ if(ret == NULL){
@ -346,6 +355,9 @@ ncsubproc* ncsubproc_createvpe(ncplane* n, const ncsubproc_options* opts,
if(!cbfxn || !donecbfxn){ if(!cbfxn || !donecbfxn){
return NULL; return NULL;
} }
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
int fd = -1; int fd = -1;
ncsubproc* ret = malloc(sizeof(*ret)); ncsubproc* ret = malloc(sizeof(*ret));
if(ret == NULL){ if(ret == NULL){

@ -290,8 +290,8 @@ ncmenu* ncmenu_create(ncplane* n, const ncmenu_options* opts){
if(opts->sectioncount <= 0 || !opts->sections){ if(opts->sectioncount <= 0 || !opts->sections){
return NULL; return NULL;
} }
if(opts->flags & ~(NCMENU_OPTION_BOTTOM)){ // HIDDEN is not yet implemented if(opts->flags > NCMENU_OPTION_HIDING){
return NULL; logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
} }
int totalheight = 1; int totalheight = 1;
int totalwidth = 2; // start with two-character margin on the left int totalwidth = 2; // start with two-character margin on the left

@ -16,6 +16,9 @@ class ncppplot {
// ought admit nullptr opts FIXME // ought admit nullptr opts FIXME
// reenable logging once #703 is done // reenable logging once #703 is done
static bool create(ncppplot<T>* ncpp, ncplane* n, const ncplot_options* opts, T miny, T maxy) { static bool create(ncppplot<T>* ncpp, ncplane* n, const ncplot_options* opts, T miny, T maxy) {
if(opts->flags > NCPLOT_OPTION_DETECTMAXONLY){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
//struct notcurses* nc = n->nc; //struct notcurses* nc = n->nc;
// if miny == maxy (enabling domain detection), they both must be equal to 0 // if miny == maxy (enabling domain detection), they both must be equal to 0
if(miny == maxy && miny){ if(miny == maxy && miny){

@ -684,10 +684,13 @@ int ncreel_redraw(ncreel* nr){
} }
static bool static bool
validate_ncreel_opts(ncplane* w, const ncreel_options* ropts){ validate_ncreel_opts(ncplane* n, const ncreel_options* ropts){
if(w == NULL){ if(n == NULL){
return false; return false;
} }
if(ropts->flags > NCREEL_OPTION_CIRCULAR){
logwarn(n->nc, "Provided unsupported flags %016lx\n", ropts->flags);
}
if(ropts->flags & NCREEL_OPTION_CIRCULAR){ if(ropts->flags & NCREEL_OPTION_CIRCULAR){
if(!(ropts->flags & NCREEL_OPTION_INFINITESCROLL)){ if(!(ropts->flags & NCREEL_OPTION_INFINITESCROLL)){
return false; // can't set circular without infinitescroll return false; // can't set circular without infinitescroll
@ -715,10 +718,10 @@ ncplane* ncreel_plane(ncreel* nr){
return nr->p; return nr->p;
} }
ncreel* ncreel_create(ncplane* w, const ncreel_options* ropts){ ncreel* ncreel_create(ncplane* n, const ncreel_options* ropts){
ncreel* nr; ncreel* nr;
if(!validate_ncreel_opts(w, ropts)){ if(!validate_ncreel_opts(n, ropts)){
return NULL; return NULL;
} }
if((nr = malloc(sizeof(*nr))) == NULL){ if((nr = malloc(sizeof(*nr))) == NULL){
@ -728,7 +731,7 @@ ncreel* ncreel_create(ncplane* w, const ncreel_options* ropts){
nr->tabletcount = 0; nr->tabletcount = 0;
nr->direction = LASTDIRECTION_DOWN; // draw down after the initial tablet nr->direction = LASTDIRECTION_DOWN; // draw down after the initial tablet
memcpy(&nr->ropts, ropts, sizeof(*ropts)); memcpy(&nr->ropts, ropts, sizeof(*ropts));
nr->p = w; nr->p = n;
nr->vft = NULL; nr->vft = NULL;
ncplane_set_base(nr->p, "", 0, ropts->bgchannel); ncplane_set_base(nr->p, "", 0, ropts->bgchannel);
if(ncreel_redraw(nr)){ if(ncreel_redraw(nr)){

@ -216,8 +216,11 @@ ncselector_dim_yx(notcurses* nc, const ncselector* n, int* ncdimy, int* ncdimx){
*ncdimx = cols; *ncdimx = cols;
} }
ncselector* ncselector_create(ncplane* nc, int y, int x, const ncselector_options* opts){ ncselector* ncselector_create(ncplane* n, int y, int x, const ncselector_options* opts){
unsigned itemcount = 0; unsigned itemcount = 0;
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
if(opts->items){ if(opts->items){
for(const struct ncselector_item* i = opts->items ; i->option ; ++i){ for(const struct ncselector_item* i = opts->items ; i->option ; ++i){
++itemcount; ++itemcount;
@ -282,8 +285,8 @@ ncselector* ncselector_create(ncplane* nc, int y, int x, const ncselector_option
} }
} }
int dimy, dimx; int dimy, dimx;
ncselector_dim_yx(nc->nc, ns, &dimy, &dimx); ncselector_dim_yx(n->nc, ns, &dimy, &dimx);
if(!(ns->ncp = ncplane_bound(nc, dimy, dimx, y, x, NULL))){ if(!(ns->ncp = ncplane_bound(n, dimy, dimx, y, x, NULL))){
goto freeitems; goto freeitems;
} }
cell_init(&ns->background); cell_init(&ns->background);
@ -794,8 +797,11 @@ ncmultiselector_dim_yx(notcurses* nc, const ncmultiselector* n, int* ncdimy, int
return 0; return 0;
} }
ncmultiselector* ncmultiselector_create(ncplane* nc, int y, int x, ncmultiselector* ncmultiselector_create(ncplane* n, int y, int x,
const ncmultiselector_options* opts){ const ncmultiselector_options* opts){
if(opts->flags > 0){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
unsigned itemcount = 0; unsigned itemcount = 0;
if(opts->items){ if(opts->items){
for(const struct ncmselector_item* i = opts->items ; i->option ; ++i){ for(const struct ncmselector_item* i = opts->items ; i->option ; ++i){
@ -849,10 +855,10 @@ ncmultiselector* ncmultiselector_create(ncplane* nc, int y, int x,
} }
} }
int dimy, dimx; int dimy, dimx;
if(ncmultiselector_dim_yx(nc->nc, ns, &dimy, &dimx)){ if(ncmultiselector_dim_yx(n->nc, ns, &dimy, &dimx)){
goto freeitems; goto freeitems;
} }
if(!(ns->ncp = ncplane_bound(nc, dimy, dimx, y, x, NULL))){ if(!(ns->ncp = ncplane_bound(n, dimy, dimx, y, x, NULL))){
goto freeitems; goto freeitems;
} }
cell_init(&ns->background); cell_init(&ns->background);

Loading…
Cancel
Save