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

commit e749a11bb7da29a13f600ac95674673240dca9fe
Author: Takashi Yano <[email protected]>
Date:   Thu Feb 19 18:28:08 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 | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 026011984..9412b67d4 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2730,6 +2730,38 @@ fhandler_pty_master::pty_master_fwd_thread (const 
master_fwd_thread_param_t *p)
            else
              state = 0;
 
+         /* Remove CSI ? 9001 h/l (win32-input-mode) */
+         int arg = 0;
+         state = 0;
+         for (DWORD i = 0; i < rlen; i++)
+           if (outbuf[i] == '\033')
+             {
+               start_at = i;
+               state = 1;
+               continue;
+             }
+           else if ((state == 1 && outbuf[i] == '[')
+                    || (state == 2 && outbuf[i] == '?'))
+             {
+               state ++;
+               continue;
+             }
+           else if (state == 3 && isdigit (outbuf[i]))
+             arg = arg * 10 + (outbuf[i] - '0');
+           else if (state == 3 && outbuf[i] == ';')
+             arg = 0;
+           else if (state == 3 && arg == 9001
+                    && (outbuf[i] == 'h' || outbuf[i] == 'l'))
+             {
+               memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);
+               rlen = wlen = start_at + rlen - i - 1;
+               state = 0;
+               i = start_at - 1;
+               continue;
+             }
+           else
+             state = 0;
+
          /* Remove OSC Ps ; ? BEL/ST */
          state = 0;
          for (DWORD i = 0; i < rlen; i++)

Reply via email to