From 0b633fbdad1dbac2c3b806d20bbdc34a8f8311dd Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 18 Dec 2020 19:11:05 -0500 Subject: [PATCH] ncplane_at_yx_cell/at_cursor_cell: return bytes of egc --- include/notcurses/notcurses.h | 9 ++++++--- src/lib/notcurses.c | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index b8bbe1f41..19eef7503 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -621,7 +621,8 @@ cell_prime(struct ncplane* n, nccell* c, const char* gcluster, return ret; } -// Duplicate 'c' into 'targ'; both must be/will be bound to 'n'. +// Duplicate 'c' into 'targ'; both must be/will be bound to 'n'. Returns -1 on +// failure, and 0 on success. API int cell_duplicate(struct ncplane* n, nccell* targ, const nccell* c); // Release resources held by the nccell 'c'. @@ -1335,7 +1336,8 @@ API int ncplane_rotate_ccw(struct ncplane* n); API char* ncplane_at_cursor(struct ncplane* n, uint16_t* stylemask, uint64_t* channels); // Retrieve the current contents of the cell under the cursor into 'c'. This -// cell is invalidated if the associated plane is destroyed. +// cell is invalidated if the associated plane is destroyed. Returns the number +// of bytes in the EGC, or -1 on error. API int ncplane_at_cursor_cell(struct ncplane* n, nccell* c); // Retrieve the current contents of the specified cell. The EGC is returned, or @@ -1345,7 +1347,8 @@ API char* ncplane_at_yx(const struct ncplane* n, int y, int x, uint16_t* stylemask, uint64_t* channels); // Retrieve the current contents of the specified cell into 'c'. This cell is -// invalidated if the associated plane is destroyed. +// invalidated if the associated plane is destroyed. Returns the number of +// bytes in the EGC, or -1 on error. API int ncplane_at_yx_cell(struct ncplane* n, int y, int x, nccell* c); // Create a flat string from the EGCs of the selected region of the ncplane diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 5bd1872c9..6a7405e08 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -239,7 +239,9 @@ int ncplane_at_yx_cell(ncplane* n, int y, int x, nccell* c){ if(y < n->leny && x < n->lenx){ if(y >= 0 && x >= 0){ nccell* targ = ncplane_cell_ref_yx(n, y, x); - return cell_duplicate(n, c, targ); + if(cell_duplicate(n, c, targ) == 0){ + return strlen(cell_extended_gcluster(n, targ)); + } } } return -1;