[newlib-cygwin] Cygwin: pty: Allow ST as a termination in pty_master_fwd_thread

Takashi Yano via Cygwin-cvs <[email protected]> Fri, 19 Dec 2025 18:29:01 +0000 (GMT)
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f840dd0a0b11498cdc206c8ad48df1975d511209

commit f840dd0a0b11498cdc206c8ad48df1975d511209
Author: Takashi Yano <[email protected]>
Date:   Wed Dec 10 10:01:24 2025 +0900

    Cygwin: pty: Allow ST as a termination in pty_master_fwd_thread
    
    In the ESC sequence parser in pty_master_fwd_thread, the termination
    ST (ESC \) was not supported for title set ESC sequence, that is, only
    BEL was detected. This patch allows ST as a termination.
    
    Fixes: 10d083c745dd ("Cygwin: pty: Inherit typeahead data between two input pipes.")
    Reviewed-by: Corinna Vinschen <[email protected]>, Johannes Schindelin <[email protected]>
    Signed-off-by: Takashi Yano <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/pty.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index be39e356a..3b0b4f073 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2680,7 +2680,7 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
 	  int state = 0;
 	  int start_at = 0;
 	  for (DWORD i=0; i<rlen; i++)
-	    if (outbuf[i] == '\033')
+	    if (state == 0 && outbuf[i] == '\033')
 	      {
 		start_at = i;
 		state = 1;
@@ -2688,12 +2688,14 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
 	      }
 	    else if ((state == 1 && outbuf[i] == ']') ||
 		     (state == 2 && outbuf[i] == '0') ||
-		     (state == 3 && outbuf[i] == ';'))
+		     (state == 3 && outbuf[i] == ';') ||
+		     (state == 4 && outbuf[i] == '\033'))
 	      {
 		state ++;
 		continue;
 	      }
-	    else if (state == 4 && outbuf[i] == '\a')
+	    else if ((state == 4 && outbuf[i] == '\a')
+		     || (state == 5 && outbuf[i] == '\\'))
 	      {
 		const char *helper_str = "\\bin\\cygwin-console-helper.exe";
 		if (memmem (&outbuf[start_at], i + 1 - start_at,
@@ -2706,7 +2708,9 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
 		state = 0;
 		continue;
 	      }
-	    else if (outbuf[i] == '\a')
+	    else if (state == 4)
+	      continue;
+	    else
 	      {
 		state = 0;
 		continue;