Re: OSC133 outputs shouldn't be printed in non-interactive mode

Daniel Colascione <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
Oliver Kiddle <[email protected]> writes:

> On 16 Jul, Daniel Colascione wrote:
>> +++ b/Test/X06termquery.ztst
>
>> +      sleep 0.1
>
> Thanks for adding the test case.
>
> Unfortunately, I don't think fractional values with sleep is portable.
> And it isn't a builtin so we depend on the system. There have been
> recent changes from others to avoid delays on other tests. Is there some
> solution that might be applued here?
>
> Oliver

Yes, we can make it much simpler. How's this version?

commit 44d3a6b3cd906e10f9bc183adf04b0e57d0fb9ad
Author: Daniel Colascione <[email protected]>
Date:   Sun Jul 12 15:52:40 2026 -0400

    Avoid OSC 133 markers in noninteractive shells

diff --git a/Src/init.c b/Src/init.c
index f36bc332b..10802669c 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -224,7 +224,7 @@ loop(int toplevel, int justonce)
 		 */
 		errflag &= ~ERRFLAG_ERROR;
 	    }
-	    if (toplevel && zle_load_state == 1)
+	    if (interact && toplevel && zle_load_state == 1)
 		zleentry(ZLE_CMD_PREEXEC);
 	    if (stopmsg)	/* unset 'you have stopped jobs' flag */
 		stopmsg--;
@@ -232,7 +232,7 @@ loop(int toplevel, int justonce)
 	    tok = toksav;
 	    if (toplevel) {
 		noexitct = 0;
-		if (zle_load_state == 1)
+		if (interact && zle_load_state == 1)
 		    zleentry(ZLE_CMD_POSTEXEC);
 	    }
 	}
diff --git a/Test/X06termquery.ztst b/Test/X06termquery.ztst
index 701cd625b..becf63c51 100644
--- a/Test/X06termquery.ztst
+++ b/Test/X06termquery.ztst
@@ -19,6 +19,19 @@
       { zpty -r zsh } | tr -d '\015' | grep -v '^ '
       zpty -d
     }
+    noninteractive_integration() {
+      local REPLY chunk out=
+      zpty -d
+      zpty zsh "${(q)ZTST_testdir}/../Src/zsh +i -f"
+      zpty -w zsh "module_path=( ${(j< >)${(@q-)module_path}} \$module_path )"
+      zpty -w zsh 'zmodload zsh/zle && print -r -- PAYLOAD'
+      zpty -w zsh exit
+      while zpty -r zsh chunk; do
+        out+=$chunk
+      done
+      zpty -d
+      [[ $out == *PAYLOAD* && $out != *$'\e]133;'* ]]
+    }
   else
     ZTST_unimplemented='the zsh/zpty module is not available'
   fi
@@ -106,6 +119,9 @@
 >replace
 >typeset -a .term.extensions=( -bracketed-paste -integration )
 
+  noninteractive_integration
+0:Noninteractive shells do not emit OSC 133 markers after loading ZLE
+
 %clean
 
   zmodload -ui zsh/zpty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.