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 59ed015a0456466ccfb9283ab51ca03e0664f341
Author: [email protected] <[email protected]>
AuthorDate: Thu Sep 24 23:32:28 2026 -0600
termpty: add a write hook
A terminal attached to a tymux session has no child process: what the
user types must go to the session's daemon instead of a pty master.
Every input path (keys, mouse reports, paste, answers to queries) ends
in termpty_write(), so a hook there redirects all of them at once
instead of touching each caller. With no hook set, nothing changes.
---
src/bin/termpty.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/termpty.h | 10 ++++++++++
src/bin/tytest.c | 1 +
src/bin/unit_tests.h | 1 +
4 files changed, 63 insertions(+)
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index b2d539ee..d1d4fc55 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1348,6 +1348,15 @@ termpty_cell_get(Termpty *ty, int y_requested, int x_requested)
return cells + x_requested;
}
+void
+termpty_write_hook_set(Termpty *ty,
+ Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
+ void *data)
+{
+ ty->write_hook.func = func;
+ ty->write_hook.data = ""
+}
+
void
termpty_write(Termpty *ty, const char *input, int len)
{
@@ -1374,6 +1383,10 @@ termpty_write(Termpty *ty, const char *input, int len)
return;
# endif
#endif
+ if (ty->write_hook.func &&
+ ty->write_hook.func(ty->write_hook.data, ty, input, len))
+ return;
+
res = ty_sb_add(&ty->write_buffer, input, len);
if (res < 0)
@@ -4864,4 +4877,42 @@ tytest_backlog_row_get_args(void)
}
#endif
+static Eina_Bool
+_ty_write_hook_capture(void *data, Termpty *ty EINA_UNUSED, const char *input, int len)
+{
+ struct ty_sb *captured = data;
+
+ ty_sb_add(captured, input, len);
+ return EINA_TRUE;
+}
+
+/* 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. */
+int
+tytest_write_hook(void)
+{
+ Termpty ty;
+ struct ty_sb captured;
+
+ _ty_test_init(&ty, 10, 5);
+ memset(&captured, 0, sizeof(captured));
+
+ termpty_write_hook_set(&ty, _ty_write_hook_capture, &captured);
+ termpty_write(&ty, "hooked", 6);
+ assert(ty.write_buffer.len == 0);
+ assert(captured.len == 6);
+ assert(!memcmp(captured.buf, "hooked", 6));
+
+ termpty_write_hook_set(&ty, NULL, NULL);
+ termpty_write(&ty, "direct", 6);
+ assert(ty.write_buffer.len == 6);
+ assert(!memcmp(ty.write_buffer.buf, "direct", 6));
+
+ ty_sb_free(&captured);
+ ty_sb_free(&ty.write_buffer);
+ _ty_test_shutdown(&ty);
+ return 0;
+}
+
#endif /* BINARY_TYFUZZ || BINARY_TYTEST */
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 17ab15ea..88e30bc4 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -245,6 +245,10 @@ struct tag_Termpty
int w, h;
int fd, slavefd;
struct ty_sb write_buffer;
+ struct {
+ Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len);
+ void *data;
+ } write_hook;
struct {
int curid;
Eina_Hash *blocks;
@@ -419,6 +423,12 @@ ssize_t termpty_row_length(Termpty *ty, int y);
#define TERMPTY_WRITE_STR(S_) \
termpty_write(ty, S_, strlen(S_))
void termpty_write(Termpty *ty, const char *input, int len);
+/* Redirect termpty_write() through FUNC instead of the real pty fd.
+ * FUNC returns EINA_TRUE when it consumed the write, EINA_FALSE to fall
+ * through to the normal pty write buffer. A NULL FUNC clears the hook. */
+void termpty_write_hook_set(Termpty *ty,
+ Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
+ 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);
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index a928f83d..b32bf361 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -33,6 +33,7 @@ static struct {
tytest_func func;
} _tytests[] = {
{ "dummy", tytest_dummy },
+ { "write_hook", tytest_write_hook},
{ "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 44eb3885..61a0a89d 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -6,6 +6,7 @@ typedef int (*tytest_func)(void);
/* list of tests */
int tytest_dummy(void);
+int tytest_write_hook(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.