implement ncplane_getc() #9

This commit is contained in:
nick black 2019-11-23 20:45:53 -05:00
parent f9b88c5079
commit 13931aee60
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 22 additions and 4 deletions

View File

@ -113,6 +113,11 @@ struct ncplane* notcurses_newplane(struct notcurses* nc, int rows, int cols,
// the standard plane. // the standard plane.
int ncplane_destroy(struct ncplane* n); int ncplane_destroy(struct ncplane* n);
// Retrieve the topmost cell at this location on the screen, returning it in
// 'c'. If there is more than a byte of gcluster, it will be returned as a heap
// allocation in '*gclust', and '*c' will be 0x80.
void notcurses_getc(const struct notcurses* n, cell* c, char** gclust);
// Manipulate the opaque user pointer associated with this plane. // Manipulate the opaque user pointer associated with this plane.
void ncplane_set_userptr(struct ncplane* n, void* opaque); void ncplane_set_userptr(struct ncplane* n, void* opaque);
void* ncplane_userptr(struct ncplane* n); void* ncplane_userptr(struct ncplane* n);
@ -156,10 +161,10 @@ void ncplane_move_bottom(struct ncplane* n);
// will only be used, if 'c->gcluster' has a value >= 0x80. // will only be used, if 'c->gcluster' has a value >= 0x80.
int ncplane_putc(struct ncplane* n, const cell* c, const char* gclust); int ncplane_putc(struct ncplane* n, const cell* c, const char* gclust);
// Retrieve the cell under the cursor, returning it in 'c'. If there is more // Retrieve the cell under this plane's cursor, returning it in 'c'. If there
// than a byte of gcluster, it will be returned as a heap allocation in // is more than a byte of gcluster, it will be returned as a heap allocation in
// '*gclust', and '*c' will be 0x80. // '*gclust', and '*c' will be 0x80. Returns -1 on error, 0 on success.
void ncplane_getc(const struct ncplane* n, cell* c, char** gclust); int ncplane_getc(const struct ncplane* n, cell* c, char** gclust);
// Write a series of cells to the current location, using the current style. // Write a series of cells to the current location, using the current style.
// They will be interpreted as a series of columns (according to the definition // They will be interpreted as a series of columns (according to the definition

View File

@ -627,6 +627,19 @@ int ncplane_putc(ncplane* n, const cell* c, const char* gclust){
return ret; return ret;
} }
int ncplane_getc(const ncplane* n, cell* c, char** gclust){
const cell* src = &n->fb[fbcellidx(n, n->y, n->x)];
memcpy(c, src, sizeof(*src));
*gclust = NULL;
if(!simple_cell_p(src)){
*gclust = strdup(extended_gcluster(n, src));
if(*gclust == NULL){
return -1;
}
}
return 0;
}
int cell_load(ncplane* n, cell* c, const char* gcluster){ int cell_load(ncplane* n, cell* c, const char* gcluster){
if(simple_gcluster_p(gcluster)){ if(simple_gcluster_p(gcluster)){
c->gcluster = *gcluster; c->gcluster = *gcluster;