From af6a37b1c4509c7766933a7cb45d2ee9a3a23f98 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 11:37:31 +0300 Subject: Return owned text and share cell attribute flags with snapshots Make text queries return allocated strings released with term_text_free, keeping each capture atomic. Align public attributes with the write core, remove snapshot conversion tables, and migrate tests and the Kitty adapter. --- src/snapshot.c | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'src/snapshot.c') diff --git a/src/snapshot.c b/src/snapshot.c index 6578c9a..8dbb498 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -87,33 +87,6 @@ static void invalidate(struct term_snapshot *s) } } -/* Attribute contributions of the low and high byte of cell flags. */ -static uint16_t lo_attrs[256], hi_attrs[256]; -static uint8_t hi_underline[256]; -void term_snapshot_tables_init(void) -{ - for (int b = 0; b < 256; b++) { - uint16_t lo = 0, hi = 0; - if (b & CELL_BOLD) lo |= TERM_ATTR_BOLD; - if (b & CELL_ITALIC) lo |= TERM_ATTR_ITALIC; - if (b & CELL_STRIKE) lo |= TERM_ATTR_STRIKE; - if (b & CELL_OVERLINE) lo |= TERM_ATTR_OVERLINE; - if (b & CELL_EMOJI) lo |= TERM_ATTR_EMOJI; - if (b & CELL_TEXT) lo |= TERM_ATTR_TEXT; - uint16_t f = (uint16_t)(b << 8); - if (f & CELL_FAINT) hi |= TERM_ATTR_FAINT; - if (f & CELL_LINK) hi |= TERM_ATTR_LINK; - uint8_t ul = 0; - if (f & CELL_DOUBLE_UNDERLINE) ul = TERM_UNDERLINE_DOUBLE; - else if (f & CELL_CURLY_UNDERLINE) ul = TERM_UNDERLINE_CURLY; - else if (f & CELL_DOTTED_UNDERLINE) ul = TERM_UNDERLINE_DOTTED; - else if (f & CELL_DASHED_UNDERLINE) ul = TERM_UNDERLINE_DASHED; - lo_attrs[b] = lo; - hi_attrs[b] = hi; - hi_underline[b] = ul; - } -} - static uint32_t arena_add(struct term_snapshot *s, const struct gstore *g, uint32_t handle, bool *ok) { @@ -148,10 +121,6 @@ static uint32_t convert_row(struct term_snapshot *s, const struct gstore *g, for (int x = 0; x < cols; x++) { const struct cell *c = &src[x]; uint16_t f = c->flags; - uint8_t lo = (uint8_t)f, hi = (uint8_t)(f >> 8); - uint16_t ul = hi_underline[hi]; - if (!ul && (f & CELL_UNDERLINE)) - ul = TERM_UNDERLINE_SINGLE; uint32_t text = c->c; if (TERM_EXPECT(text < 0x20, 0)) text = text ? ' ' : 0; @@ -164,8 +133,7 @@ static uint32_t convert_row(struct term_snapshot *s, const struct gstore *g, .text = text, .fg = c->fg, .bg = c->bg, - .attrs = (uint16_t)(lo_attrs[lo] | hi_attrs[hi] | - ul << TERM_ATTR_UNDERLINE_SHIFT), + .attrs = (uint16_t)(f & ~(CELL_WIDE | CELL_TRAIL | CELL_WRAP_PAD)), .width = (f & CELL_TRAIL) ? 0 : (f & CELL_WIDE) ? 2 : 1, }; } -- cgit v1.2.3