summaryrefslogtreecommitdiff
path: root/src/selection.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 11:37:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 11:37:31 +0300
commitaf6a37b1c4509c7766933a7cb45d2ee9a3a23f98 (patch)
treee7b0294ebf0d9b124b8885a76c119d7f46d5b0fb /src/selection.c
parentacd338ea33de36d223cc6d301712eed4a9501e6c (diff)
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.
Diffstat (limited to 'src/selection.c')
-rw-r--r--src/selection.c29
1 files changed, 7 insertions, 22 deletions
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 <stdlib.h>
#include <string.h>
-/* 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;
}