From 0645fb3931a5da6edd2d98f5cdb9b9194ce7c8e4 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 4 Dec 2020 03:06:51 -0500 Subject: [PATCH] run cell_load_char()/egc32() through cell_load() #1176 --- include/notcurses/notcurses.h | 23 +++++++++-------------- tests/wide.cpp | 4 ++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index b2627c6e6..187be7efa 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -729,22 +729,20 @@ cellcmp(const struct ncplane* n1, const cell* RESTRICT c1, // Load a 7-bit char 'ch' into the cell 'c'. static inline int cell_load_char(struct ncplane* n, cell* c, char ch){ - cell_release(n, c); - // FIXME don't allow non-printing garbage - c->channels &= ~(CELL_WIDEASIAN_MASK | CELL_NOBACKGROUND_MASK); - c->gcluster = htole((uint32_t)ch); - return 1; + char gcluster[2]; + gcluster[0] = ch; + gcluster[1] = '\0'; + return cell_load(n, c, gcluster); } // Load a UTF-8 encoded EGC of up to 4 bytes into the cell 'c'. static inline int cell_load_egc32(struct ncplane* n, cell* c, uint32_t egc){ - cell_release(n, c); - // FIXME don't allow non-printing garbage, nor invalid forms - // FIXME this might well be a wide egc, augh - c->channels &= ~(CELL_WIDEASIAN_MASK | CELL_NOBACKGROUND_MASK); - c->gcluster = htole(egc); - return 1; + char gcluster[sizeof(egc) + 1]; + egc = htole(egc); + memcpy(gcluster, &egc, sizeof(egc)); + gcluster[4] = '\0'; + return cell_load(n, c, gcluster); } // These log levels consciously map cleanly to those of libav; Notcurses itself @@ -1406,9 +1404,6 @@ ncplane_putc(struct ncplane* n, const cell* c){ return ncplane_putc_yx(n, -1, -1, c); } -// Replace the EGC underneath us, but retain the styling. The current styling -// of the plane will not be changed. -// // Replace the cell at the specified coordinates with the provided 7-bit char // 'c'. Advance the cursor by 1. On success, returns 1. On failure, returns -1. // This works whether the underlying char is signed or unsigned. diff --git a/tests/wide.cpp b/tests/wide.cpp index 58bfb7b1a..1b3260b94 100644 --- a/tests/wide.cpp +++ b/tests/wide.cpp @@ -104,8 +104,8 @@ TEST_CASE("Wide") { } } - // Placing a wide char to the immediate left of any other char ought obliterate - // that cell. + // Placing a wide char to the immediate left of any other char ought + // obliterate that cell. SUBCASE("WideCharAnnihilatesRight") { const char* w = FROG; const char* wbashed = SCORPION;