https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b7541ef1242ac2e5d46fb1ac8704024f99042c47

commit b7541ef1242ac2e5d46fb1ac8704024f99042c47
Author: Takashi Yano <[email protected]>
Date:   Thu Feb 19 17:13:55 2026 +0900

    Cygwin: pty: Omit win32-input-mode sequence from pseudo console
    
    In Windows 11, pseudo console uses CSI?9001h which lets the terminal
    enter win32-input-mode in console. As a result, two problems happen.
    
    1) If non-cygwin app is running in script command on the console,
       Ctrl-C terminates not only the non-cygwin app, but also script
       command without cleanup for the pseudo console.
    
    2) Some remnants sequences from win32-input-mode occasionally
       appears on the shell in script command on the console.
    
    This patch fixes them by omit CSI?9001h to prevent the terminal
    from entering win32-input-mode.
    
    Signed-off-by: Takashi Yano <[email protected]>
    Suggested-by: Johannes Schindelin <[email protected]>
    Reviewed-by: Johannes Schindelin <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/pty.cc | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 88a3d1cfe..b59f54096 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2692,8 +2692,12 @@ workarounds_for_pseudo_console_output (char *outbuf, 
DWORD rlen)
        assert (state == 2);
        if (outbuf[i-1] == '[' && outbuf[i] == '>')
          saw_greater_than_sign = true;
-       else if (isdigit (outbuf[i]) || outbuf[i] == ';')
-         continue;
+       else if (outbuf[i-1] == '[' && outbuf[i] == '?')
+         saw_question_mark = true;
+       else if (isdigit (outbuf[i]))
+         arg = arg * 10 + (outbuf[i] - '0');
+       else if (outbuf[i] == ';')
+         arg = 0;
        else if (saw_greater_than_sign && outbuf[i] == 'm')
          {
            /* Remove CSI > Pm m */
@@ -2722,6 +2726,14 @@ workarounds_for_pseudo_console_output (char *outbuf, 
DWORD rlen)
              }
            state = 0;
          }
+       else if (saw_question_mark && arg == 9001
+                && (outbuf[i] == 'h' || outbuf[i] == 'l'))
+         {
+           memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);
+           rlen = start_at + rlen - i - 1;
+           i = start_at - 1;
+           state = 0;
+         }
        else if (outbuf[i] == '\033')
          {
            start_at = i;
@@ -2734,6 +2746,8 @@ workarounds_for_pseudo_console_output (char *outbuf, 
DWORD rlen)
          {
            is_csi = false;
            saw_greater_than_sign = false;
+           saw_question_mark = false;
+           arg = 0;
          }
       }
     else if (is_osc)

Reply via email to