From 13572136f1924f99475795b306bca0edbcb16087 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 6 Sep 2020 23:00:28 -0400 Subject: [PATCH] ncreader: handle NCREADER_OPTION_CURSOR in create/destroy #962 --- src/lib/internal.h | 1 + src/lib/reader.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 52d58cdee..38599b18b 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -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 { diff --git a/src/lib/reader.c b/src/lib/reader.c index b9f3130d7..32cc167ff 100644 --- a/src/lib/reader.c +++ b/src/lib/reader.c @@ -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);