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/selection.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'src/selection.c') diff --git a/src/selection.c b/src/selection.c index 2727e8a..3ac2ee3 100644 --- a/src/selection.c +++ b/src/selection.c @@ -5,14 +5,6 @@ #include #include -/* Copies a heap string into buf and frees it. Returns the length without the NUL. */ -static size_t text_out(char *text, char *buf, size_t cap) -{ - size_t n = term_copy_out(text, buf, cap); - free(text); - return n; -} - static char *link_at_text(const struct term *t, struct term_vector2i cell) { int col = cell.x, row = cell.y; @@ -62,14 +54,13 @@ static char *link_at_text(const struct term *t, struct term_vector2i cell) return out; } -size_t term_link_at(const struct term *t, struct term_vector2i cell, char *buf, size_t cap) +char *term_link_at(const struct term *t, struct term_vector2i cell) { - if (!t) - return 0; + if (!t) return NULL; term_write_begin((struct term *)t); char *text = link_at_text(t, cell); term_write_end((struct term *)t); - return text_out(text, buf, cap); + return text; } void term_select_clear(struct term *t) @@ -775,7 +766,7 @@ static char *range_text_inner(const struct term *t, return text; } -static char *history_text(struct term *t, int max_rows) +char *term_history_text(struct term *t, int max_rows) { if (!t) return NULL; @@ -822,17 +813,11 @@ static char *history_text(struct term *t, int max_rows) return text; } -size_t term_history_text(struct term *t, int max_rows, char *buf, size_t cap) +char *term_selection_text(const struct term *t) { - return text_out(history_text(t, max_rows), buf, cap); -} - -size_t term_selection_text(const struct term *t, char *buf, size_t cap) -{ - if (!t) - return 0; + if (!t) return NULL; term_write_begin((struct term *)t); char *text = range_text_inner(t, NULL); term_write_end((struct term *)t); - return text_out(text, buf, cap); + return text; } -- cgit v1.2.3