implement ncplane_getc() #9

pull/15/head
nick black 5 years ago
parent f9b88c5079
commit 13931aee60
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -113,6 +113,11 @@ struct ncplane* notcurses_newplane(struct notcurses* nc, int rows, int cols,
// the standard plane.
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.
void ncplane_set_userptr(struct ncplane* n, void* opaque);
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.
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
// than a byte of gcluster, it will be returned as a heap allocation in
// '*gclust', and '*c' will be 0x80.
void ncplane_getc(const struct ncplane* n, cell* c, char** gclust);
// Retrieve the cell under this plane's cursor, 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. Returns -1 on error, 0 on success.
int ncplane_getc(const struct ncplane* n, cell* c, char** gclust);
// 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

@ -627,6 +627,19 @@ int ncplane_putc(ncplane* n, const cell* c, const char* gclust){
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){
if(simple_gcluster_p(gcluster)){
c->gcluster = *gcluster;

Loading…
Cancel
Save