Skip to content

Commit e749a11

Browse files
committed
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 <takashi.yano@nifty.ne.jp> Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
1 parent 224317e commit e749a11

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

winsup/cygwin/fhandler/pty.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,38 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
27302730
else
27312731
state = 0;
27322732

2733+
/* Remove CSI ? 9001 h/l (win32-input-mode) */
2734+
int arg = 0;
2735+
state = 0;
2736+
for (DWORD i = 0; i < rlen; i++)
2737+
if (outbuf[i] == '\033')
2738+
{
2739+
start_at = i;
2740+
state = 1;
2741+
continue;
2742+
}
2743+
else if ((state == 1 && outbuf[i] == '[')
2744+
|| (state == 2 && outbuf[i] == '?'))
2745+
{
2746+
state ++;
2747+
continue;
2748+
}
2749+
else if (state == 3 && isdigit (outbuf[i]))
2750+
arg = arg * 10 + (outbuf[i] - '0');
2751+
else if (state == 3 && outbuf[i] == ';')
2752+
arg = 0;
2753+
else if (state == 3 && arg == 9001
2754+
&& (outbuf[i] == 'h' || outbuf[i] == 'l'))
2755+
{
2756+
memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);
2757+
rlen = wlen = start_at + rlen - i - 1;
2758+
state = 0;
2759+
i = start_at - 1;
2760+
continue;
2761+
}
2762+
else
2763+
state = 0;
2764+
27332765
/* Remove OSC Ps ; ? BEL/ST */
27342766
state = 0;
27352767
for (DWORD i = 0; i < rlen; i++)

0 commit comments

Comments
 (0)