This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 847dce05ba3f9ba64dfc978947fe042618de143c
Author: [email protected] <[email protected]>
AuthorDate: Fri Sep 25 09:34:54 2026 -0600
termpty: add a hook reporting rows saved to the backlog
tymuxd needs to forward the lines that scroll off its screen to its
clients. The hook reports each row as termpty_text_save_top() receives
it, after autowrap marking, both when it starts a new backlog entry and
when it extends a wrapped one. A client that feeds the same rows to its
own termpty_text_save_top() rebuilds the same entries, wrapped lines
included, so no line wider than the screen ever has to be sent.
The early returns taken when termpty_save_expand() or termpty_save_new()
fail now release the backlog lock like the other paths do. The lock
functions are empty today, so this changes nothing yet.
With no hook set, which is every terminal but tymuxd, the cost is one
NULL test per saved row. tybench on the scroll corpus, which saves a row
per line, goes from 75.4 to 76.5 MB/s, and the six other corpora differ
by +1.5% to -0.1%, all within the run to run spread. Release build on an
AMD Ryzen 7 6800U; medians of seven alternating runs of
`tybench -i 15` over the corpora of tests/bench/gen_corpus.py.
---
src/bin/termpty.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++-
src/bin/termpty.h | 15 +++++
src/bin/tytest.c | 2 +
src/bin/unit_tests.h | 2 +
4 files changed, 180 insertions(+), 1 deletion(-)
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index d1d4fc55..039ee9bb 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1120,9 +1120,14 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
if (ts->w && ts->cells[ts->w - 1].att.autowrapped)
{
int old_len = ts->w;
- termpty_save_expand(ty, ts, cells, w);
+
+ if (!termpty_save_expand(ty, ts, cells, w))
+ return;
ty->backlog_beacon.screen_y += DIV_ROUND_UP(ts->w, ty->w)
- DIV_ROUND_UP(old_len, ty->w);
+
+ if (ty->backlog_hook.func)
+ ty->backlog_hook.func(ty->backlog_hook.data, ty, cells, w);
return;
}
}
@@ -1137,6 +1142,9 @@ add_new_ts:
if (ty->backpos >= ty->backsize)
ty->backpos = 0;
+ if (ty->backlog_hook.func)
+ ty->backlog_hook.func(ty->backlog_hook.data, ty, cells, w);
+
ty->backlog_beacon.screen_y++;
ty->backlog_beacon.backlog_y++;
if (ty->backlog_beacon.backlog_y >= (int)ty->backsize)
@@ -1348,6 +1356,15 @@ termpty_cell_get(Termpty *ty, int y_requested, int x_requested)
return cells + x_requested;
}
+void
+termpty_backlog_hook_set(Termpty *ty,
+ void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w),
+ void *data)
+{
+ ty->backlog_hook.func = func;
+ ty->backlog_hook.data = ""
+}
+
void
termpty_write_hook_set(Termpty *ty,
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
@@ -4886,6 +4903,149 @@ _ty_write_hook_capture(void *data, Termpty *ty EINA_UNUSED, const char *input, i
return EINA_TRUE;
}
+static void
+_ty_backlog_hook_capture(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssize_t w)
+{
+ int *count = data;
+
+ (*count)++;
+ assert(cells);
+ assert(w >= 0);
+}
+
+/* Test: termpty_text_save_top() calls the backlog hook exactly once per
+ * call that saves a row, whether it starts a new backlog entry or extends
+ * the wrapped entry already at its top -- so a caller replaying the hook's
+ * calls through termpty_text_save_top() reproduces the same merge. */
+int
+tytest_backlog_hook(void)
+{
+ Termpty ty;
+ Termcell cells[10];
+ int count = 0;
+ int j;
+
+ _ty_test_init(&ty, 10, 5);
+ termpty_backlog_size_set(&ty, 20);
+ memset(cells, 0, sizeof(cells));
+ /* a full-width row: termpty_line_length() trims trailing empty cells,
+ * so cells[9] (checked below) must be non-empty to count as the last
+ * cell of a 10-wide row. */
+ for (j = 0; j < 10; j++)
+ cells[j].codepoint = 'a';
+ /* the row saved by this call ends up at the top of the backlog with its
+ * last cell autowrapped, so the *next* save extends it instead of
+ * starting a new entry. */
+ cells[9].att.autowrapped = 1;
+
+ termpty_backlog_hook_set(&ty, _ty_backlog_hook_capture, &count);
+ termpty_text_save_top(&ty, cells, 10);
+ assert(count == 1);
+ assert(termpty_backlog_length(&ty) == 1);
+
+ /* extends the entry saved above instead of starting a new one --
+ * termpty_backlog_length() counts screen rows, and the merged entry now
+ * spans two of them, but the hook must still fire, once, for the
+ * extension. Its own last cell is not autowrapped, so nothing after it
+ * merges further. */
+ cells[9].att.autowrapped = 0;
+ termpty_text_save_top(&ty, cells, 10);
+ assert(count == 2);
+ assert(termpty_backlog_length(&ty) == 2);
+
+ termpty_text_save_top(&ty, cells, 10);
+ assert(count == 3);
+ assert(termpty_backlog_length(&ty) == 3);
+
+ /* a blank row has no cells to report and is reported all the same */
+ memset(cells, 0, sizeof(cells));
+ termpty_text_save_top(&ty, cells, 10);
+ assert(count == 4);
+ assert(termpty_backlog_length(&ty) == 4);
+
+ termpty_backlog_hook_set(&ty, NULL, NULL);
+ termpty_text_save_top(&ty, cells, 10);
+ assert(count == 4);
+ assert(termpty_backlog_length(&ty) == 5);
+
+ _ty_test_shutdown(&ty);
+ return 0;
+}
+
+/* Test: a logical line spanning several wrapped rows arrives intact on the
+ * other end when every hook call is replayed through
+ * termpty_text_save_top() again: the hook reports each row (not the merged
+ * Termsave), each row at most the screen width wide, so a client rebuilds
+ * the exact same merged entry instead of only the first physical row of the
+ * wrapped line. A blank row after it is replayed as a blank entry. */
+static void
+_ty_backlog_hook_replay(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssize_t w)
+{
+ Termpty *dst = data;
+
+ termpty_text_save_top(dst, (Termcell *)cells, w);
+}
+
+int
+tytest_backlog_hook_wrap_replay(void)
+{
+ Termpty src, dst;
+ Termcell cells[10];
+ const Termsave *src_ts, *dst_ts;
+ int i;
+
+ _ty_test_init(&src, 10, 5);
+ _ty_test_init(&dst, 10, 5);
+ termpty_backlog_size_set(&src, 20);
+ termpty_backlog_size_set(&dst, 20);
+
+ termpty_backlog_hook_set(&src, _ty_backlog_hook_replay, &dst);
+
+ /* three screen-width rows of a single wrapped logical line: the first
+ * two carry the autowrap flag on their last cell. */
+ for (i = 0; i < 3; i++)
+ {
+ int j;
+
+ memset(cells, 0, sizeof(cells));
+ for (j = 0; j < 10; j++)
+ cells[j].codepoint = (unsigned int)('0' + i);
+ if (i < 2)
+ cells[9].att.autowrapped = 1;
+ termpty_text_save_top(&src, cells, 10);
+ }
+
+ /* the whole line merged into one backlog entry on both sides, spanning
+ * the three screen-width rows it was made of */
+ assert(termpty_backlog_length(&src) == 3);
+ assert(termpty_backlog_length(&dst) == 3);
+
+ {
+ Termpty *ty = &src;
+ src_ts = BACKLOG_ROW_GET(ty, 1);
+ }
+ {
+ Termpty *ty = &dst;
+ dst_ts = BACKLOG_ROW_GET(ty, 1);
+ }
+ assert(src_ts->w == 30);
+ assert(dst_ts->w == 30);
+ for (i = 0; i < 30; i++)
+ assert(src_ts->cells[i].codepoint == dst_ts->cells[i].codepoint);
+
+ memset(cells, 0, sizeof(cells));
+ termpty_text_save_top(&src, cells, 10);
+ {
+ Termpty *ty = &dst;
+ assert(termpty_backlog_length(&dst) == termpty_backlog_length(&src));
+ assert(BACKLOG_ROW_GET(ty, 1)->w == 0);
+ }
+
+ _ty_test_shutdown(&src);
+ _ty_test_shutdown(&dst);
+ return 0;
+}
+
/* Test: termpty_write() calls the hook when one is set, instead of
* queuing the data for the real pty fd, and falls through to the real
* pty write buffer once the hook is cleared. */
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 88e30bc4..e6954d30 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -249,6 +249,10 @@ struct tag_Termpty
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len);
void *data;
} write_hook;
+ struct {
+ void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w);
+ void *data;
+ } backlog_hook;
struct {
int curid;
Eina_Hash *blocks;
@@ -430,6 +434,17 @@ void termpty_write_hook_set(Termpty *ty,
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
void *data);
+/* Called every time termpty_text_save_top() saves a row into the backlog,
+ * whether it starts a new backlog entry or extends the wrapped entry
+ * already at its top. CELLS/W are the row exactly as passed to
+ * termpty_text_save_top() (after autowrap marking), not the possibly wider
+ * merged Termsave it ends up part of: replaying every call through
+ * termpty_text_save_top() again reproduces the same backlog, and each call
+ * is at most the screen width wide. A NULL FUNC clears the hook. */
+void termpty_backlog_hook_set(Termpty *ty,
+ void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w),
+ void *data);
+
void termpty_resize(Termpty *ty, int new_w, int new_h);
void termpty_resize_tabs(Termpty *ty, int old_w, int new_w);
void termpty_backscroll_adjust(Termpty *ty, int *scroll);
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 12489aa4..969a3487 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -34,6 +34,8 @@ static struct {
} _tytests[] = {
{ "dummy", tytest_dummy },
{ "write_hook", tytest_write_hook},
+ { "backlog_hook", tytest_backlog_hook},
+ { "backlog_hook_wrap_replay", tytest_backlog_hook_wrap_replay},
{ "simd_parity", tytest_simd_parity},
{ "rgb_to_palette", tytest_rgb_to_palette},
{ "colors_is_dark", tytest_colors_is_dark},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index d434b268..852a4547 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -7,6 +7,8 @@ typedef int (*tytest_func)(void);
/* list of tests */
int tytest_dummy(void);
int tytest_write_hook(void);
+int tytest_backlog_hook(void);
+int tytest_backlog_hook_wrap_replay(void);
int tytest_simd_parity(void);
int tytest_rgb_to_palette(void);
int tytest_colors_is_dark(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.