ncreader: handle NCREADER_OPTION_CURSOR in create/destroy #962

pull/1005/head
nick black 4 years ago committed by Nick Black
parent 784b0a4e2a
commit 13572136f1

@ -196,6 +196,7 @@ typedef struct ncreader {
int xproject; // virtual x location of ncp origin on textarea
bool horscroll; // is there horizontal panning?
bool no_cmd_keys; // are shortcuts disabled?
bool manage_cursor; // enable and place the terminal cursor
} ncreader;
typedef struct ncmenu {

@ -5,9 +5,8 @@ ncreader* ncreader_create(ncplane* n, int y, int x, const ncreader_options* opts
logerror(n->nc, "Provided illegal geometry %dx%d\n", opts->physcols, opts->physrows);
return NULL;
}
if(opts->flags > NCREADER_OPTION_HORSCROLL){
logerror(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
return NULL;
if(opts->flags > NCREADER_OPTION_CURSOR){
logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
}
ncreader* nr = malloc(sizeof(*nr));
if(nr){
@ -33,8 +32,17 @@ ncreader* ncreader_create(ncplane* n, int y, int x, const ncreader_options* opts
nr->tchannels = opts->tchannels;
nr->tattrs = opts->tattrword;
nr->no_cmd_keys = opts->flags & NCREADER_OPTION_NOCMDKEYS;
nr->manage_cursor = opts->flags & NCREADER_OPTION_CURSOR;
ncplane_set_channels(nr->ncp, opts->tchannels);
ncplane_set_attr(nr->ncp, opts->tattrword);
if(nr->manage_cursor){
if(notcurses_cursor_enable(n->nc, nr->ncp->absy, nr->ncp->absx)){
ncplane_destroy(nr->textarea);
ncplane_destroy(nr->ncp);
free(nr);
return NULL;
}
}
}
return nr;
}
@ -279,6 +287,9 @@ void ncreader_destroy(ncreader* n, char** contents){
if(contents){
*contents = ncreader_contents(n);
}
if(n->manage_cursor){
notcurses_cursor_disable(n->ncp->nc);
}
ncplane_destroy(n->textarea);
ncplane_destroy(n->ncp);
free(n);

Loading…
Cancel
Save