ncreader: handle NCREADER_OPTION_CURSOR in create/destroy #962

This commit is contained in:
nick black 2020-09-06 23:00:28 -04:00 committed by Nick Black
parent 784b0a4e2a
commit 13572136f1
2 changed files with 15 additions and 3 deletions

View File

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

View File

@ -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); logerror(n->nc, "Provided illegal geometry %dx%d\n", opts->physcols, opts->physrows);
return NULL; return NULL;
} }
if(opts->flags > NCREADER_OPTION_HORSCROLL){ if(opts->flags > NCREADER_OPTION_CURSOR){
logerror(n->nc, "Provided unsupported flags %016lx\n", opts->flags); logwarn(n->nc, "Provided unsupported flags %016lx\n", opts->flags);
return NULL;
} }
ncreader* nr = malloc(sizeof(*nr)); ncreader* nr = malloc(sizeof(*nr));
if(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->tchannels = opts->tchannels;
nr->tattrs = opts->tattrword; nr->tattrs = opts->tattrword;
nr->no_cmd_keys = opts->flags & NCREADER_OPTION_NOCMDKEYS; 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_channels(nr->ncp, opts->tchannels);
ncplane_set_attr(nr->ncp, opts->tattrword); 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; return nr;
} }
@ -279,6 +287,9 @@ void ncreader_destroy(ncreader* n, char** contents){
if(contents){ if(contents){
*contents = ncreader_contents(n); *contents = ncreader_contents(n);
} }
if(n->manage_cursor){
notcurses_cursor_disable(n->ncp->nc);
}
ncplane_destroy(n->textarea); ncplane_destroy(n->textarea);
ncplane_destroy(n->ncp); ncplane_destroy(n->ncp);
free(n); free(n);