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 97bd07647eaf0d3cdc09d1ed57ef49b12abf6ff8
Author: [email protected] <[email protected]>
AuthorDate: Fri Sep 25 10:28:08 2026 -0600

    termio: open a tymux session in a new tab on request
    
    tymux attach --new-tab NAME, inside Terminology, asks for the session
    in a new tab instead of replacing the shell it runs in, with the
    private command ESC } atn;NAME NUL (atns; for a shared client, atnr;
    for a read-only one). Like at;, it is ignored when Terminology escapes
    are disabled.
    
    The tab is opened the way the new tab action opens one from that
    terminal, so it lands where that action would put it, in a split too,
    and its terminal is attached to the session from the start rather than
    running a shell first. termio_add() and term_new() take the attach mode
    next to the session name for that; termsrv.h does not depend on EFL,
    so their headers use TermSrvAttachMode directly. If the session cannot
    be attached, no tab is added.
    
    Outside Terminology, --new-tab fails instead of falling back to the
    inline proxy, which would take over the very terminal the user wanted
    to keep.
    
    tymux_attach_escape.sh gains the new forms, which changes its checksum;
    the sequences it already had are unchanged.
---
 README.md                    |  6 ++++
 man/tymux.1                  | 17 +++++++++-
 src/bin/main.c               |  2 ++
 src/bin/main.h               |  6 ++++
 src/bin/termio.c             | 67 +++++++++++++++++++++++++++++++++------
 src/bin/termio.h             |  9 ++++--
 src/bin/termiointernals.h    |  3 ++
 src/bin/termtymux.c          | 66 ++++++++++++++++++++++++++++-----------
 src/bin/termtymux.h          | 12 +++++--
 src/bin/tymux.c              | 52 ++++++++++++++++++++++++-------
 src/bin/win.c                | 74 ++++++++++++++++++++++++++++++++++++--------
 src/bin/win.h                | 10 ++++--
 tests/tests.results          |  2 +-
 tests/tymux.py               | 35 ++++++++++++++++++++-
 tests/tymux_attach_escape.sh | 28 ++++++++++++++---
 15 files changed, 322 insertions(+), 67 deletions(-)

diff --git a/README.md b/README.md
index fb44fc3f..ffe2c9fa 100644
--- a/README.md
+++ b/README.md
@@ -201,6 +201,12 @@ Examples:
     with no `;` (e.g. `atoff`) is the alpha command above, not a hand-off;
     an unrecognized or malformed hand-off is ignored.
 
+  * `atn;[NAME]`, `atns;[NAME]`, `atnr;[NAME]`
+    native tymux new-tab hand-off: like `at;`/`ats;`/`atr;` above, but
+    opens a new tab already attached to `NAME` instead of replacing this
+    terminal's pty, which is left running whatever it was running (see
+    `tymux attach --new-tab` in `tymux(1)`).
+
   * `qs`
   query grid and font size. stdin will have written to it:
     `W;H;FW;FH\n`
diff --git a/man/tymux.1 b/man/tymux.1
index 69de0936..7a8bc331 100644
--- a/man/tymux.1
+++ b/man/tymux.1
@@ -8,6 +8,7 @@ tymux \- keep shells running in the background and use them from any terminal
 .br
 .B tymux attach
 .RB [ \-s | \-r ]
+.RB [ \-\-new\-tab ]
 .I NAME
 .br
 .B tymux list
@@ -57,7 +58,7 @@ A name may not start with \fB\-\fP, contain \fB/\fP or be longer than 64
 bytes.
 .
 .TP
-.BR attach " [" \-s | \-r "] \fINAME\fP"
+.BR attach " [" \-s | \-r "] [" \-\-new\-tab "] \fINAME\fP"
 Attach the current terminal to \fINAME\fP, pausing the terminal that was in
 control.
 .RS
@@ -67,6 +68,14 @@ Do not take over: type along with the terminal in control.
 .TP
 .B \-r, \-\-readonly
 Only watch: what is typed is ignored.
+.TP
+.B \-\-new\-tab
+Open a new tab attached to \fINAME\fP instead of switching the current
+terminal, which is left running whatever it was running. Only works as a
+native hand-off (see \fBNATIVE HAND\-OFF\fP): outside Terminology, or with
+\fBTYMUX_NO_NATIVE\fP set, there is no tab to open into, so
+.B tymux
+fails instead of falling back to the inline proxy.
 .RE
 .
 .TP
@@ -141,6 +150,12 @@ if this is a concern, e.g. when scripting
 .B tymux attach
 from a context where that cannot be guaranteed.
 .PP
+.B \-\-new\-tab
+asks Terminology to open a new tab instead of replacing the current
+terminal's shell; the terminal that ran
+.B tymux attach \-\-new\-tab
+is left untouched and does not receive \fBSIGHUP\fP.
+.PP
 Since a hand-off targets whatever terminal reads standard output, running
 .B tymux attach
 or
diff --git a/src/bin/main.c b/src/bin/main.c
index 8c6996c4..56795e31 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -446,6 +446,7 @@ main_ipc_new(Ipc_Instance *inst)
 #else
                    , NULL
 #endif
+                   , TSRV_ATTACH_HIJACK
                   );
    if (!term)
      {
@@ -646,6 +647,7 @@ _start(Ipc_Instance *instance, Eina_Bool need_scale_wizard)
 #else
                    , NULL
 #endif
+                   , TSRV_ATTACH_HIJACK
                   );
    if (!term)
      {
diff --git a/src/bin/main.h b/src/bin/main.h
index 9ff533eb..d1fefbac 100644
--- a/src/bin/main.h
+++ b/src/bin/main.h
@@ -2,10 +2,16 @@
 #define TERMINOLOGY_MAIN_H_ 1
 
 #include "config.h"
+/* EFL-free (see its own header comment), so safe to include here even in
+ * a build without HAVE_TYMUX, just for the TermSrvAttachMode type below. */
+#include "termsrv.h"
 
 Config * main_config_get(void);
 void main_new(Evas_Object *term);
 void main_new_with_dir(Evas_Object *win, Evas_Object *term, const char *wdir);
+/* See win.c's main_new_tymux(). */
+void main_new_tymux(Evas_Object *term, const char *tymux_name,
+                    TermSrvAttachMode tymux_mode);
 void main_split_h(Evas_Object *win, Evas_Object *term, const char *cmd);
 void main_split_v(Evas_Object *win, Evas_Object *term, const char *cmd);
 void term_close(Evas_Object *win, Evas_Object *term,
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 82188d52..aca760f4 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -3936,6 +3936,8 @@ _smart_del(Evas_Object *obj)
 #ifdef HAVE_TYMUX
    if (sd->tymux_switch_job) ecore_job_del(sd->tymux_switch_job);
    eina_stringshare_del(sd->tymux_pending);
+   if (sd->tymux_newtab_job) ecore_job_del(sd->tymux_newtab_job);
+   eina_stringshare_del(sd->tymux_newtab_pending);
    if (sd->tymux) termtymux_free(sd->tymux); /* also frees sd->pty */
    else if (sd->pty) termpty_free(sd->pty);
 #else
@@ -4396,6 +4398,45 @@ _termio_tymux_switch(Evas_Object *obj, Termio *sd, const char *tymux_name,
    if (!sd->tymux_switch_job)
      sd->tymux_switch_job = ecore_job_add(_termio_tymux_switch_job, obj);
 }
+
+/* Deferred new-tab hand-off, run on the next main loop iteration for the
+ * same reason as _termio_tymux_switch_job(): we are called from deep
+ * inside this terminal's own read handling, and win.c's tab creation
+ * must not run from within it. Unlike the plain hand-off, the terminal
+ * that received the escape is left untouched; a new tab is opened next
+ * to it already attached to the session. */
+static void
+_termio_tymux_newtab_job(void *data)
+{
+   Evas_Object *obj = data;
+   Termio *sd = evas_object_smart_data_get(obj);
+   const char *tymux_name;
+   TermSrvAttachMode mode;
+
+   if (!sd) return;
+   sd->tymux_newtab_job = NULL;
+   tymux_name = sd->tymux_newtab_pending;
+   if (!tymux_name) return;
+   sd->tymux_newtab_pending = NULL;
+   mode = sd->tymux_newtab_pending_mode;
+
+   main_new_tymux(obj, tymux_name, mode);
+   eina_stringshare_del(tymux_name);
+}
+
+/* Native new-tab hand-off: 'tymux attach --new-tab'/'tymux new', when run
+ * inside this terminal, ask Terminology to open a new tab attached to the
+ * session directly instead of switching this terminal. See tymux.c for
+ * the escape emitted. */
+static void
+_termio_tymux_newtab(Evas_Object *obj, Termio *sd, const char *tymux_name,
+                     TermSrvAttachMode mode)
+{
+   eina_stringshare_replace(&sd->tymux_newtab_pending, tymux_name);
+   sd->tymux_newtab_pending_mode = mode;
+   if (!sd->tymux_newtab_job)
+     sd->tymux_newtab_job = ecore_job_add(_termio_tymux_newtab_job, obj);
+}
 #endif
 
 static void
@@ -4422,27 +4463,34 @@ _smart_pty_command(void *data)
      return;
 
 #ifdef HAVE_TYMUX
-   /* at;NAME / ats;NAME / atr;NAME - native tymux hand-off, gated by
+   /* at;NAME / ats;NAME / atr;NAME - native tymux hand-off, and its
+    * atn;NAME / atns;NAME / atnr;NAME new-tab variants (open a new tab
+    * attached to NAME instead of switching this terminal), gated by
     * ty_escapes like every other private command family below (alpha,
     * images, popmedia, background, sendfile): untrusted output (a `cat`
     * of a file, an ssh MOTD, a CI log) must not be able to switch the
-    * terminal to a tymux session and SIGHUP its shell when the user has
-    * Terminology escapes turned off.
+    * terminal to a tymux session and SIGHUP its shell, nor open new tabs,
+    * when the user has Terminology escapes turned off.
     *
     * cur_cmd[0..1] == "at" also matches the pre-existing 'at[on/true/…]'
     * temporary-alpha command (see win.c _cb_command()), so only consume
     * the escape here when it actually parses as a hand-off (its argument
     * always has a ';' where an alpha value never does); anything else,
-    * including malformed hand-offs and the atn* new-tab family (not yet
-    * implemented), falls through to the normal handling below. */
+    * including malformed hand-offs, falls through to the normal handling
+    * below. */
    if (ty->cur_cmd[0] == 'a' && ty->cur_cmd[1] == 't')
      {
         const char *name;
         TermSrvAttachMode mode;
+        Eina_Bool new_tab;
 
-        if (termtymux_attach_escape_parse(&ty->cur_cmd[2], &name, &mode))
+        if (termtymux_attach_escape_parse(&ty->cur_cmd[2], &name, &mode,
+                                          &new_tab))
           {
-             _termio_tymux_switch(obj, sd, name, mode);
+             if (new_tab)
+               _termio_tymux_newtab(obj, sd, name, mode);
+             else
+               _termio_tymux_switch(obj, sd, name, mode);
              return;
           }
      }
@@ -4907,7 +4955,7 @@ Evas_Object *
 termio_add(Evas_Object *win, Config *config,
            const char *cmd, Eina_Bool login_shell, const char *cd,
            int w, int h, Term *term, const char *title,
-           const char *tymux_name)
+           const char *tymux_name, TermSrvAttachMode tymux_mode)
 {
    Evas *e;
    Evas_Object *obj, *g;
@@ -4916,6 +4964,7 @@ termio_add(Evas_Object *win, Config *config,
 
 #ifndef HAVE_TYMUX
    (void)tymux_name;
+   (void)tymux_mode;
 #endif
    EINA_SAFETY_ON_NULL_RETURN_VAL(win, NULL);
    e = evas_object_evas_get(win);
@@ -4965,7 +5014,7 @@ termio_add(Evas_Object *win, Config *config,
    if (tymux_name)
      {
         sd->tymux = termtymux_new(tymux_name, w, h, config,
-                                  TSRV_ATTACH_HIJACK, &sd->pty);
+                                  tymux_mode, &sd->pty);
         if (!sd->tymux)
           {
              ERR(_("Could not attach to tymux session '%s'"), tymux_name);
diff --git a/src/bin/termio.h b/src/bin/termio.h
index 31261027..e1c25fca 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -9,13 +9,18 @@
 #include "win.h"
 #endif
 #include "termiointernals.h"
+/* EFL-free (see its own header comment), so safe to include here even in
+ * a build without HAVE_TYMUX, just for the TermSrvAttachMode type below. */
+#include "termsrv.h"
 
 /* tymux_name, when set, attaches to that tymux session instead of spawning
  * cmd: a shadow pty mirrors the session's screen and forwards input to it.
- * NULL for a normal terminal. */
+ * NULL for a normal terminal, in which case tymux_mode is ignored. */
 Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd,
                         Eina_Bool login_shell, const char *cd, int w, int h,
-                        Term *term, const char *title, const char *tymux_name);
+                        Term *term, const char *title, const char *tymux_name,
+                        TermSrvAttachMode tymux_mode);
+
 /* Whether obj's pty is a tymux shadow pty currently hijacked by another
  * client. Always EINA_FALSE for a normal terminal or when built without
  * HAVE_TYMUX. */
diff --git a/src/bin/termiointernals.h b/src/bin/termiointernals.h
index de669720..6126f23d 100644
--- a/src/bin/termiointernals.h
+++ b/src/bin/termiointernals.h
@@ -125,6 +125,9 @@ struct tag_Termio
    const char *tymux_pending;      /* eina_stringshare; deferred switch target */
    TermSrvAttachMode tymux_pending_mode;
    Ecore_Job *tymux_switch_job;
+   const char *tymux_newtab_pending; /* eina_stringshare; deferred new-tab target */
+   TermSrvAttachMode tymux_newtab_pending_mode;
+   Ecore_Job *tymux_newtab_job;
 #endif
    Ecore_Animator *anim;
    Ecore_Timer *delayed_size_timer;
diff --git a/src/bin/termtymux.c b/src/bin/termtymux.c
index 36745108..d9c3afed 100644
--- a/src/bin/termtymux.c
+++ b/src/bin/termtymux.c
@@ -501,17 +501,21 @@ termtymux_paused_get(const TermTymux *ts)
  * pre-existing 'at[on/true/yes/off/false/no]' temporary-alpha command
  * (win.c _cb_command(), values "on"/"true"/"yes"/"off"/"false"/"no")
  * lives: none of those values contain ';', so requiring one right after
- * the optional 's'/'r' variant letter is what tells the two apart. Do
+ * the optional 'n'/'s'/'r' variant letters is what tells the two apart. Do
  * not relax this without checking that set of alpha values first. */
 Eina_Bool
 termtymux_attach_escape_parse(const char *arg, const char **name,
-                              TermSrvAttachMode *mode)
+                              TermSrvAttachMode *mode, Eina_Bool *new_tab)
 {
    TermSrvAttachMode m = TSRV_ATTACH_HIJACK;
+   Eina_Bool nt = EINA_FALSE;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(arg, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(new_tab, EINA_FALSE);
+
+   if (*arg == 'n') { nt = EINA_TRUE; arg++; }
 
    if (*arg == 's') { m = TSRV_ATTACH_SHARED; arg++; }
    else if (*arg == 'r') { m = TSRV_ATTACH_READONLY; arg++; }
@@ -522,6 +526,7 @@ termtymux_attach_escape_parse(const char *arg, const char **name,
 
    *name = arg;
    *mode = m;
+   *new_tab = nt;
    return EINA_TRUE;
 }
 
@@ -797,46 +802,71 @@ tytest_termtymux_input_chunks_send(void)
    return 0;
 }
 
-/* Test: the "at"/"ats"/"atr" hand-off escape argument parses to the right
- * name and mode, and malformed or invalid variants are rejected. */
+/* Test: the "at"/"ats"/"atr" hand-off escape argument, and its "atn"/
+ * "atns"/"atnr" new-tab variants, parse to the right name, mode and
+ * new_tab flag, and malformed or invalid variants are rejected. */
 int
 tytest_termtymux_attach_escape_parse(void)
 {
    const char *name;
    TermSrvAttachMode mode;
+   Eina_Bool new_tab;
 
-   assert(termtymux_attach_escape_parse(";work", &name, &mode));
+   assert(termtymux_attach_escape_parse(";work", &name, &mode, &new_tab));
    assert(!strcmp(name, "work"));
    assert(mode == TSRV_ATTACH_HIJACK);
+   assert(!new_tab);
 
-   assert(termtymux_attach_escape_parse("s;work", &name, &mode));
+   assert(termtymux_attach_escape_parse("s;work", &name, &mode, &new_tab));
    assert(!strcmp(name, "work"));
    assert(mode == TSRV_ATTACH_SHARED);
+   assert(!new_tab);
 
-   assert(termtymux_attach_escape_parse("r;work", &name, &mode));
+   assert(termtymux_attach_escape_parse("r;work", &name, &mode, &new_tab));
    assert(!strcmp(name, "work"));
    assert(mode == TSRV_ATTACH_READONLY);
+   assert(!new_tab);
+
+   /* new-tab variants */
+   assert(termtymux_attach_escape_parse("n;work", &name, &mode, &new_tab));
+   assert(!strcmp(name, "work"));
+   assert(mode == TSRV_ATTACH_HIJACK);
+   assert(new_tab);
+
+   assert(termtymux_attach_escape_parse("ns;work", &name, &mode, &new_tab));
+   assert(!strcmp(name, "work"));
+   assert(mode == TSRV_ATTACH_SHARED);
+   assert(new_tab);
+
+   assert(termtymux_attach_escape_parse("nr;work", &name, &mode, &new_tab));
+   assert(!strcmp(name, "work"));
+   assert(mode == TSRV_ATTACH_READONLY);
+   assert(new_tab);
 
    /* missing ';' */
-   assert(!termtymux_attach_escape_parse("work", &name, &mode));
+   assert(!termtymux_attach_escape_parse("work", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("nwork", &name, &mode, &new_tab));
    /* empty name */
-   assert(!termtymux_attach_escape_parse(";", &name, &mode));
+   assert(!termtymux_attach_escape_parse(";", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("n;", &name, &mode, &new_tab));
    /* unknown variant letter */
-   assert(!termtymux_attach_escape_parse("x;work", &name, &mode));
+   assert(!termtymux_attach_escape_parse("x;work", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("nx;work", &name, &mode, &new_tab));
    /* invalid name (path traversal) */
-   assert(!termtymux_attach_escape_parse(";../x", &name, &mode));
+   assert(!termtymux_attach_escape_parse(";../x", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("n;../x", &name, &mode, &new_tab));
 
    /* the pre-existing 'at[on/true/yes/off/false/no]' alpha command (see
     * win.c _cb_command()) must never be taken for a hand-off: none of its
     * values contain ';' */
-   assert(!termtymux_attach_escape_parse("on", &name, &mode));
-   assert(!termtymux_attach_escape_parse("true", &name, &mode));
-   assert(!termtymux_attach_escape_parse("yes", &name, &mode));
-   assert(!termtymux_attach_escape_parse("off", &name, &mode));
-   assert(!termtymux_attach_escape_parse("false", &name, &mode));
-   assert(!termtymux_attach_escape_parse("no", &name, &mode));
+   assert(!termtymux_attach_escape_parse("on", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("true", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("yes", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("off", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("false", &name, &mode, &new_tab));
+   assert(!termtymux_attach_escape_parse("no", &name, &mode, &new_tab));
    /* a bare numeric alpha value, e.g. from a future extension */
-   assert(!termtymux_attach_escape_parse("128", &name, &mode));
+   assert(!termtymux_attach_escape_parse("128", &name, &mode, &new_tab));
 
    return 0;
 }
diff --git a/src/bin/termtymux.h b/src/bin/termtymux.h
index de41f764..4c61b9a2 100644
--- a/src/bin/termtymux.h
+++ b/src/bin/termtymux.h
@@ -98,10 +98,16 @@ Eina_Bool termtymux_paused_get(const TermTymux *ts);
  *   ";NAME"   -> TSRV_ATTACH_HIJACK
  *   "s;NAME"  -> TSRV_ATTACH_SHARED
  *   "r;NAME"  -> TSRV_ATTACH_READONLY
+ * "n<variant>;NAME" asks for a new tab attached to NAME instead of
+ * switching the current terminal (see tymux.c's --new-tab option):
+ *   "n;NAME"  -> TSRV_ATTACH_HIJACK, new_tab
+ *   "ns;NAME" -> TSRV_ATTACH_SHARED, new_tab
+ *   "nr;NAME" -> TSRV_ATTACH_READONLY, new_tab
  * NAME is validated with termsrv_name_check(). On success, name points
- * into arg (no copy) and mode is set; returns EINA_FALSE and leaves
- * both untouched for a malformed variant or an invalid name. */
+ * into arg (no copy), mode and new_tab are set; returns EINA_FALSE and
+ * leaves all three untouched for a malformed variant or an invalid name. */
 Eina_Bool termtymux_attach_escape_parse(const char *arg, const char **name,
-                                        TermSrvAttachMode *mode);
+                                        TermSrvAttachMode *mode,
+                                        Eina_Bool *new_tab);
 
 #endif
diff --git a/src/bin/tymux.c b/src/bin/tymux.c
index 4f40b1e8..a8c4f834 100644
--- a/src/bin/tymux.c
+++ b/src/bin/tymux.c
@@ -674,11 +674,14 @@ _native_handoff_allowed(void)
 }
 
 /* Emits Terminology's private native hand-off escape and returns true if
- * it was sent: the caller must exit without running the inline proxy, as
- * Terminology receiving it replaces this process's controlling terminal
- * with a shadow pty and closing our pty master will end us via SIGHUP. */
+ * it was sent. For new_tab == false, the caller must exit without running
+ * the inline proxy, as Terminology receiving it replaces this process's
+ * controlling terminal with a shadow pty and closing our pty master will
+ * end us via SIGHUP. For new_tab == true this process's own terminal is
+ * left untouched (Terminology opens a new tab instead), so the caller
+ * exits normally once the escape is sent. */
 static bool
-_native_handoff_try(const char *name, TermSrvAttachMode mode)
+_native_handoff_try(const char *name, TermSrvAttachMode mode, bool new_tab)
 {
    char esc[128];
    const char *variant;
@@ -688,9 +691,15 @@ _native_handoff_try(const char *name, TermSrvAttachMode mode)
 
    switch (mode)
      {
-      case TSRV_ATTACH_SHARED:   variant = "ats;"; break;
-      case TSRV_ATTACH_READONLY: variant = "atr;"; break;
-      default:                   variant = "at;"; break;
+      case TSRV_ATTACH_SHARED:
+        variant = new_tab ? "atns;" : "ats;";
+        break;
+      case TSRV_ATTACH_READONLY:
+        variant = new_tab ? "atnr;" : "atr;";
+        break;
+      default:
+        variant = new_tab ? "atn;" : "at;";
+        break;
      }
    n = snprintf(esc, sizeof(esc), "\033}%s%s", variant, name);
    if (n <= 0 || (size_t)n >= sizeof(esc)) return false;
@@ -702,7 +711,7 @@ _native_handoff_try(const char *name, TermSrvAttachMode mode)
 }
 
 static int
-_attach(const char *name, TermSrvAttachMode mode)
+_attach(const char *name, TermSrvAttachMode mode, bool new_tab)
 {
    const char *current = getenv("TYMUX_NAME");
    uint8_t mode_byte = mode;
@@ -718,11 +727,23 @@ _attach(const char *name, TermSrvAttachMode mode)
      }
    /* Checked liveness above so we never hand off a session that does not
     * exist; Terminology has no way to report that failure back to us. */
-   if (_native_handoff_try(name, mode))
+   if (_native_handoff_try(name, mode, new_tab))
      {
         close(sock);
         return 0;
      }
+   if (new_tab)
+     {
+        /* Opening a new tab only makes sense as a hand-off to a running
+         * Terminology: the inline proxy below takes over *this* terminal,
+         * which is the opposite of what --new-tab asked for. Fail loudly
+         * instead of silently falling back to a plain attach. */
+        fprintf(stderr,
+                "tymux: --new-tab only works inside Terminology"
+                " (see tymux(1))\n");
+        close(sock);
+        return 1;
+     }
    if (termsrv_msg_send(sock, TSRV_MSG_ATTACH, &mode_byte, 1) < 0)
      {
         perror("tymux: send");
@@ -744,6 +765,7 @@ _cmd_attach(int argc, char **argv)
 {
    TermSrvAttachMode mode = TSRV_ATTACH_HIJACK;
    const char *name = NULL;
+   bool new_tab = false;
    int i;
 
    for (i = 2; i < argc; i++)
@@ -752,6 +774,8 @@ _cmd_attach(int argc, char **argv)
           mode = TSRV_ATTACH_SHARED;
         else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--readonly"))
           mode = TSRV_ATTACH_READONLY;
+        else if (!strcmp(argv[i], "--new-tab"))
+          new_tab = true;
         else if (argv[i][0] == '-' || name)
           {
              fprintf(stderr, "tymux attach: unexpected argument '%s'\n",
@@ -763,10 +787,12 @@ _cmd_attach(int argc, char **argv)
      }
    if (!name)
      {
-        fprintf(stderr, "Usage: tymux attach [--shared|--readonly] NAME\n");
+        fprintf(stderr,
+                "Usage: tymux attach [--shared|--readonly] [--new-tab]"
+                " NAME\n");
         return 1;
      }
-   return _attach(name, mode);
+   return _attach(name, mode, new_tab);
 }
 
 static int
@@ -795,7 +821,7 @@ _cmd_new(int argc, char **argv)
         fprintf(stderr, "tymux: could not start tymuxd for '%s'\n", name);
         return 1;
      }
-   return _attach(name, TSRV_ATTACH_HIJACK);
+   return _attach(name, TSRV_ATTACH_HIJACK, false);
 }
 
 static int
@@ -883,6 +909,8 @@ _usage(const char *argv0)
           "                        terminal it was attached to\n"
           "    -s, --shared        Type along with the other terminals\n"
           "    -r, --readonly      Only watch\n"
+          "    --new-tab           Open a new tab instead (only works\n"
+          "                        inside Terminology)\n"
           "  list                  List the running shells\n"
           "  kill NAME             Hang up the shell called NAME\n"
           "\n"
diff --git a/src/bin/win.c b/src/bin/win.c
index 0af90a94..1283c329 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -231,7 +231,7 @@ static void _term_media_update(Term *term, const Config *config);
 static void _term_miniview_check(Term *term);
 static void _popmedia_queue_process(Term *term);
 static void _cb_size_hint(void *data, Evas *_e EINA_UNUSED, Evas_Object *obj, void *_event EINA_UNUSED);
-static void _tab_new_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED);
+static void _tab_new_with(Tabs *tabs, const char *tymux_name, TermSrvAttachMode tymux_mode);
 static Tab_Item* tab_item_new(Tabs *tabs, Term_Container *child);
 static void _tabs_recreate(Tabs *tabs);
 static void _tab_drag_free(void);
@@ -536,11 +536,11 @@ _solo_close(Term_Container *tc,
 }
 
 static void
-_solo_tabs_new(Term_Container *tc)
+_solo_tabs_new(Term_Container *tc, const char *tymux_name, TermSrvAttachMode tymux_mode)
 {
    if (tc->parent->type != TERM_CONTAINER_TYPE_TABS)
      _tabs_new(tc, tc->parent);
-   _tab_new_cb(tc->parent, NULL, NULL);
+   _tab_new_with((Tabs *)tc->parent, tymux_name, tymux_mode);
 }
 
 static void
@@ -1678,7 +1678,7 @@ _win_split(Term_Container *tc, Term_Container *child,
           }
         tm_new = term_new(wn, wn->config,
                           cmd, wn->config->login_shell, wdir,
-                          80, 24, EINA_FALSE, NULL, NULL);
+                          80, 24, EINA_FALSE, NULL, NULL, TSRV_ATTACH_HIJACK);
         tc_solo_new = _solo_new(tm_new, wn);
         evas_object_data_set(tm_new->termio, "sizedone", tm_new->termio);
 
@@ -3100,7 +3100,7 @@ _split_split(Term_Container *tc, Term_Container *child,
      }
    tm_new = term_new(wn, wn->config,
                      cmd, wn->config->login_shell, wdir,
-                     80, 24, EINA_FALSE, NULL, NULL);
+                     80, 24, EINA_FALSE, NULL, NULL, TSRV_ATTACH_HIJACK);
    tc_solo_new = _solo_new(tm_new, wn);
    evas_object_data_set(tm_new->termio, "sizedone", tm_new->termio);
 
@@ -5281,12 +5281,11 @@ _tabs_swallow(Term_Container *tc, Term_Container *orig,
 }
 
 
+/* tymux_name, when set, opens the new tab already attached to that
+ * session (see term_new()) instead of spawning a shell. */
 static void
-_tab_new_cb(void *data,
-            Evas_Object *_obj EINA_UNUSED,
-            void *_event_info EINA_UNUSED)
+_tab_new_with(Tabs *tabs, const char *tymux_name, TermSrvAttachMode tymux_mode)
 {
-   Tabs *tabs = data;
    Term_Container *tc = (Term_Container*) tabs,
                   *tc_new;
    Term *tm_new;
@@ -5308,7 +5307,16 @@ _tab_new_cb(void *data,
 
    tm_new = term_new(wn, wn->config,
                      NULL, wn->config->login_shell, wdir,
-                     80, 24, EINA_FALSE, NULL, NULL);
+                     80, 24, EINA_FALSE, NULL, tymux_name, tymux_mode);
+   if (!tm_new)
+     {
+        /* term_new() already logged why (termio_add() failing to attach
+         * to tymux_name is the only realistic cause here, cmd is NULL).
+         * Nothing was attached to tabs yet, so there is no half-built tab
+         * to undo. */
+        ERR(_("Could not create new tab"));
+        return;
+     }
    tc_new = _solo_new(tm_new, wn);
    evas_object_data_set(tm_new->termio, "sizedone", tm_new->termio);
 
@@ -5325,7 +5333,7 @@ _cb_new(void *data,
 
    assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
 
-   _solo_tabs_new(tc);
+   _solo_tabs_new(tc, NULL, TSRV_ATTACH_HIJACK);
    _focus_validator();
 }
 
@@ -5351,6 +5359,45 @@ main_new(Evas_Object *term)
    _cb_new(tm, term, NULL);
 }
 
+/* Opens a new tab next to termio, already attached to the tymux session
+ * tymux_name (tymux_mode is a TermSrvAttachMode), for the "atn"/"atns"/
+ * "atnr" native hand-off escape.
+ *
+ * This mirrors _cb_new() (the ordinary "new tab" action, keyboard
+ * shortcut/menu/tab-bar "+") exactly, tymux arguments aside: term's own
+ * container (term->container) is *always* TERM_CONTAINER_TYPE_SOLO no
+ * matter where that terminal sits (_solo_new() is the only place that
+ * sets Term::container, so this holds whether the terminal is a lone
+ * solo, already in a tab, alone in a split with no tab bar, or a split
+ * pane inside a tab), so _solo_tabs_new() alone already handles all of
+ * those layouts by only ever looking at tc->parent's type: it wraps just
+ * this SOLO leaf in a fresh Tabs when tc->parent isn't one already
+ * (whatever tc->parent is — the window itself, or the SPLIT this pane
+ * lives in — that call is what "new tab" always does to a split pane),
+ * or reuses tc->parent directly when it is. There is deliberately no
+ * separate tree-walk here: reusing the exact call _cb_new() makes keeps
+ * this path exercised by ordinary interactive use instead of adding a
+ * second, untested way to create a tab.
+ *
+ * Called from an ecore_job (see termio.c's _termio_tymux_newtab_job()),
+ * never from inside the escape parser: it may replace termio's tab
+ * layout (_tabs_new()) and that must not happen while termio is still on
+ * the call stack that delivered the escape to it. */
+void
+main_new_tymux(Evas_Object *term, const char *tymux_name, TermSrvAttachMode tymux_mode)
+{
+   Term *tm;
+   Term_Container *tc;
+
+   tm = evas_object_data_get(term, "term");
+   if (!tm) return;
+   tc = tm->container;
+   assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
+
+   _solo_tabs_new(tc, tymux_name, tymux_mode);
+   _focus_validator();
+}
+
 static void
 _tabs_focus(Term_Container *tc, Term_Container *relative)
 {
@@ -7854,7 +7901,7 @@ Term *
 term_new(Win *wn, Config *config, const char *cmd,
          Eina_Bool login_shell, const char *cd,
          int size_w, int size_h, Eina_Bool hold,
-         const char *title, const char *tymux_name)
+         const char *title, const char *tymux_name, TermSrvAttachMode tymux_mode)
 {
    Term *term;
    Evas_Object *o;
@@ -7909,7 +7956,8 @@ term_new(Win *wn, Config *config, const char *cmd,
    _term_trans(term);
 
    term->termio = o = termio_add(wn->win, config, cmd, login_shell, cd,
-                                 size_w, size_h, term, title, tymux_name);
+                                 size_w, size_h, term, title, tymux_name,
+                                 tymux_mode);
    if (!o)
      {
         /* termio_add() already logged why (e.g. a tymux attach failure);
diff --git a/src/bin/win.h b/src/bin/win.h
index b4e90a73..ebe00c7f 100644
--- a/src/bin/win.h
+++ b/src/bin/win.h
@@ -2,6 +2,9 @@
 #define TERMINOLOGY_WIN_H_ 1
 
 #include "config.h"
+/* EFL-free (see its own header comment), so safe to include here even in
+ * a build without HAVE_TYMUX, just for the TermSrvAttachMode type below. */
+#include "termsrv.h"
 
 typedef struct tag_Win   Win;
 typedef struct tag_Term  Term;
@@ -38,10 +41,13 @@ void windows_free(void);
 void windows_update(void);
 
 /* tymux_name, when set, shows that tymux session instead of spawning cmd:
- * see termio_add(). NULL for a normal terminal. */
+ * see termio_add(). NULL for a normal terminal, in which case tymux_mode
+ * is ignored. Returns NULL, having torn down anything it allocated, if
+ * termio_add() fails (e.g. attaching to tymux_name did). */
 Term *term_new(Win *wn, Config *config, const char *cmd,
                Eina_Bool login_shell, const char *cd, int size_w, int size_h,
-               Eina_Bool hold, const char *title, const char *tymux_name);
+               Eina_Bool hold, const char *title, const char *tymux_name,
+               TermSrvAttachMode tymux_mode);
 int win_term_set(Win *wn, Term *term);
 
 Eina_List *
diff --git a/tests/tests.results b/tests/tests.results
index 6095daab..c9bbaa78 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -249,4 +249,4 @@ kitty-kbd-reset.sh bd10ee95b6b71d150fbe1a11c7b6ac94
 kitty-kbd-unsupported.sh 63cfb663085848fd972e9ba667a2901b
 kitty-kbd-malformed.sh 70f115545d4cda821177c842c2f96a7f
 ind_nel_blank_line.sh 0824297732e75e03e7c37de4efd225a5
-tymux_attach_escape.sh b40d9c814826baa47436decabd511bb3
+tymux_attach_escape.sh 983ab3dfbb930a91fb8d5cbdb46648eb
diff --git a/tests/tymux.py b/tests/tymux.py
index 7b956b76..af2cf9e9 100644
--- a/tests/tymux.py
+++ b/tests/tymux.py
@@ -797,9 +797,42 @@ def main():
           result.stdout == b"\033}at;" + NAME3.encode() + b"\0",
           "hand-off: 'tymux new' also hands off the freshly created session")
 
+    # --new-tab: same variants, with an 'n' inserted right after "at".
+    result = subprocess.run([TYMUX, "attach", "--new-tab", NAME2],
+                            env=term_env, capture_output=True, timeout=10)
+    check(result.returncode == 0 and
+          result.stdout == b"\033}atn;" + NAME2.encode() + b"\0",
+          "hand-off: --new-tab emits the atn; variant")
+
+    result = subprocess.run(
+        [TYMUX, "attach", "--new-tab", "--readonly", NAME2],
+        env=term_env, capture_output=True, timeout=10)
+    check(result.stdout == b"\033}atnr;" + NAME2.encode() + b"\0",
+          "hand-off: --new-tab --readonly emits the atnr; variant")
+
+    result = subprocess.run(
+        [TYMUX, "attach", "--new-tab", "--shared", NAME2],
+        env=term_env, capture_output=True, timeout=10)
+    check(result.stdout == b"\033}atns;" + NAME2.encode() + b"\0",
+          "hand-off: --new-tab --shared emits the atns; variant")
+
+    # Outside Terminology, --new-tab cannot work (there is no tab to open
+    # into): it must fail loudly instead of silently proxying.
+    result = subprocess.run([TYMUX, "attach", "--new-tab", NAME2], env=ENV,
+                            capture_output=True, timeout=10)
+    check(result.returncode == 1 and result.stdout == b"" and
+          b"--new-tab" in result.stderr,
+          "--new-tab outside Terminology fails instead of proxying")
+
     # TYMUX_NO_NATIVE is the escape hatch: even with TERMINOLOGY set, the
-    # inline proxy runs as if nothing was set.
+    # inline proxy runs as if nothing was set. It also defeats --new-tab,
+    # which must then fail loudly rather than fall back to the proxy.
     noenv = dict(term_env, TYMUX_NO_NATIVE="1")
+    result = subprocess.run([TYMUX, "attach", "--new-tab", NAME2],
+                            env=noenv, capture_output=True, timeout=10)
+    check(result.returncode == 1 and b"--new-tab" in result.stderr,
+          "--new-tab with TYMUX_NO_NATIVE fails instead of proxying")
+
     forced = Client(["attach", NAME2], env=noenv)
     check(forced.expect("$ "), "hand-off: TYMUX_NO_NATIVE forces the proxy")
     forced.send("\x02d")
diff --git a/tests/tymux_attach_escape.sh b/tests/tymux_attach_escape.sh
index 7d4a8693..586e99fc 100644
--- a/tests/tymux_attach_escape.sh
+++ b/tests/tymux_attach_escape.sh
@@ -2,9 +2,12 @@
 # shellcheck source=tests/utils.sh
 . "$(dirname "$0")/utils.sh"
 
-# Terminology's private native tymux hand-off escape ("\033}at[s|r];NAME\0",
-# emitted by 'tymux attach'/'tymux new' when run inside Terminology, see
-# termtymux_attach_escape_parse() and _termio_tymux_switch() in termio.c).
+# Terminology's private native tymux hand-off escape
+# ("\033}at[n][s|r];NAME\0", emitted by 'tymux attach'/'tymux new' when
+# run inside Terminology, see termtymux_attach_escape_parse() and
+# _termio_tymux_switch()/_termio_tymux_newtab() in termio.c). The 'n'
+# variants (atn;/atns;/atnr;) ask for a new tab instead of switching the
+# current terminal (see 'tymux attach --new-tab' in tymux(1)).
 #
 # tytest has no termio object, so ty->cb.command.func is never set and
 # these sequences are always swallowed by _handle_esc_terminology() without
@@ -40,7 +43,22 @@ printf 'E'
 printf '\033}atx;work\000'
 printf 'F'
 
-# atn (new-tab) prefix: not a hand-off form, must still be swallowed
-# rather than acted on or mis-parsed
+# new-tab, hijack
 printf '\033}atn;work\000'
 printf 'G'
+
+# new-tab, shared
+printf '\033}atns;work\000'
+printf 'H'
+
+# new-tab, readonly
+printf '\033}atnr;work\000'
+printf 'I'
+
+# new-tab, empty name
+printf '\033}atn;\000'
+printf 'J'
+
+# new-tab, unknown variant letter after 'n'
+printf '\033}atnx;work\000'
+printf 'K'

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to