From 95ba340fba0f2f2e21878c0d70a42d0f9a8b7c87 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 9 May 2020 01:25:00 -0400 Subject: [PATCH] ncplane_erase: fix bug in basecell preservation --- USAGE.md | 2 +- doc/man/man3/notcurses_plane.3.md | 3 +++ include/notcurses/notcurses.h | 2 +- src/lib/notcurses.c | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 355d45ea2..5326d4aa6 100644 --- a/USAGE.md +++ b/USAGE.md @@ -544,7 +544,7 @@ int ncplane_mergedown(struct ncplane* restrict src, struct ncplane* restrict dst // Erase every cell in the ncplane, resetting all attributes to normal, all // colors to the default color, and all cells to undrawn. All cells associated // with this ncplane are invalidated, and must not be used after the call, -// excluding the base cell. +// excluding the base cell. The cursor is homed. void ncplane_erase(struct ncplane* n); ``` diff --git a/doc/man/man3/notcurses_plane.3.md b/doc/man/man3/notcurses_plane.3.md index 7b0227356..85b97c4b8 100644 --- a/doc/man/man3/notcurses_plane.3.md +++ b/doc/man/man3/notcurses_plane.3.md @@ -196,6 +196,9 @@ expressed relative to the standard plane, and returns coordinates relative to of the rendering region. Only those cells where **src** intersects with **dst** might see changes. It is an error to merge a plane onto itself. +**ncplane_erase** zeroes out every cell of the plane, dumps the egcpool, and +homes the cursor. The base cell is preserved. + ## Scrolling All planes, including the standard plane, are created with scrolling disabled. diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index f57e32609..9af09a3db 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1629,7 +1629,7 @@ API int ncplane_mergedown(struct ncplane* RESTRICT src, struct ncplane* RESTRICT // Erase every cell in the ncplane, resetting all attributes to normal, all // colors to the default color, and all cells to undrawn. All cells associated // with this ncplane is invalidated, and must not be used after the call, -// excluding the base cell. +// *excluding* the base cell. The cursor is homed. API void ncplane_erase(struct ncplane* n); #define NCPALETTESIZE 256 diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index dbb97fea1..30e11bf14 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1773,8 +1773,10 @@ void ncplane_erase(ncplane* n){ memset(n->fb, 0, sizeof(*n->fb) * n->lenx * n->leny); egcpool_dump(&n->pool); egcpool_init(&n->pool); + cell_init(&n->basecell); cell_load(n, &n->basecell, egc); free(egc); + n->y = n->x = 0; } void notcurses_cursor_enable(notcurses* nc){