From 35aa7f6e8562a25114a2b5c0a485018a54e38584 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 31 Dec 2019 21:29:57 -0500 Subject: [PATCH] move cell_egc_copy() to internal.h --- include/notcurses.h | 1 + src/lib/internal.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/notcurses.h b/include/notcurses.h index c28fdb7a5..93441c0f4 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -457,6 +457,7 @@ API int ncplane_at_cursor(struct ncplane* n, cell* c); // Retrieve the cell at the specified location on the specified plane, returning // it in 'c'. This copy is safe to use until the ncplane is destroyed/erased. +// Returns the length of the EGC in bytes. API int ncplane_at_yx(struct ncplane* n, int y, int x, cell* c); // Manipulate the opaque user pointer associated with this plane. diff --git a/src/lib/internal.h b/src/lib/internal.h index 90b2e207a..59e59add7 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -209,6 +210,22 @@ fbcellidx(const ncplane* n, int row, int col){ return row * n->lenx + col; } +// copy the UTF8-encoded EGC out of the cell, whether simple or complex. the +// result is not tied to the ncplane, and persists across erases / destruction. +static inline char* +cell_egc_copy(const ncplane* n, const cell* c){ + char* ret; + if(cell_simple_p(c)){ + if( (ret = (char*)malloc(2)) ){ // cast required for c++ unit tests + ret[0] = c->gcluster; + ret[1] = '\0'; + } + }else{ + ret = strdup(cell_extended_gcluster(n, c)); + } + return ret; +} + // For our first attempt, O(1) uniform conversion from 8-bit r/g/b down to // ~2.4-bit 6x6x6 cube + greyscale (assumed on entry; I know no way to // even semi-portably recover the palette) proceeds via: map each 8-bit to