track wide char as reported by wcwidth(), add unit test #6

pull/51/head
nick black 5 years ago
parent b91d867b29
commit 7aaa0fcce1
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -45,7 +45,8 @@ typedef struct cell {
uint32_t attrword; // + 4b -> 8b
// (channels & 0x8000000000000000ull): inherit styling from prior cell
// (channels & 0x4000000000000000ull): foreground is *not* "default color"
// (channels & 0x3f00000000000000ull): reserved, must be 0
// (channels & 0x2000000000000000ull): wide character (left or right side)
// (channels & 0x1f00000000000000ull): reserved, must be 0
// (channels & 0x00ffffff00000000ull): foreground in 3x8 RGB (rrggbb)
// (channels & 0x0000000080000000ull): in the middle of a multicolumn glyph
// (channels & 0x0000000040000000ull): background is *not* "default color"
@ -295,6 +296,7 @@ cell_rgb_blue(uint32_t rgb){
}
#define CELL_FGDEFAULT_MASK 0x4000000000000000ull
#define CELL_WIDEASIAN_MASK 0x2000000000000000ull
#define CELL_BGDEFAULT_MASK 0x0000000040000000ull
static inline void
@ -349,6 +351,11 @@ cell_bg_default_p(const cell* c){
return !(c->channels & CELL_BGDEFAULT_MASK);
}
static inline bool
cell_wide_p(const cell* c){
return (c->channels & CELL_WIDEASIAN_MASK);
}
#ifdef __cplusplus
} // extern "C"
#endif

@ -695,6 +695,11 @@ int cell_load(ncplane* n, cell* c, const char* gcluster){
c->gcluster = *gcluster;
return !!c->gcluster;
}
if(cols > 1){
c->channels |= CELL_WIDEASIAN_MASK;
}else{
c->channels &= ~CELL_WIDEASIAN_MASK;
}
size_t ulen;
// FIXME feed in already-calculated lengths from prior utf8_egc_len()!
int eoffset = egcpool_stash(&n->pool, gcluster, &ulen, &cols);

@ -256,3 +256,18 @@ TEST_F(NcplaneTest, CellDuplicateCombining) {
cell_release(n_, &cell5);
cell_release(n_, &cell6);
}
TEST_F(NcplaneTest, CellMultiColumn) {
const char* w1 = "👨";
const char* w2 = "N";
cell c1 = CELL_TRIVIAL_INITIALIZER;
cell c2 = CELL_TRIVIAL_INITIALIZER;
auto u1 = cell_load(n_, &c1, w1);
auto u2 = cell_load(n_, &c2, w2);
ASSERT_EQ(strlen(w1), u1);
ASSERT_EQ(strlen(w2), u2);
EXPECT_TRUE(cell_wide_p(&c1));
EXPECT_FALSE(cell_wide_p(&c2));
cell_release(n_, &c1);
cell_release(n_, &c2);
}

Loading…
Cancel
Save